Unformatted text preview:

Topic 5Implementing ClassesImplementing Classes“And so, from Europe, we get things such ,p,gg... object-oriented analysis and design (a clever way of breaking up software programming instructions and data into small, reusable objects, based on certain bt ti i il dd iabstraction principles and design hierarchies.)”-Michael A Cusumano-Michael A. Cusumano, The Business Of SoftwareCS 307 Fundamentals of Computer ScienceImplementing Classes1DefinitionsDefinitionsCS 307 Fundamentals of Computer ScienceImplementing Classes2Object Oriented ProgrammingWh i bj i d i ?What is object oriented programming?"Object-oriented programming is a method of ib d hi hfl dprogramming based on a hierarchy of classes, and well-defined and cooperating objects. "What is a class?What is a class?"A class is a structure that defines the data and the methods to work on that data When you writemethods to work on that data. When you write programs in the Java language, all program data is wrapped in a class, whether it is a class you writewrapped in a class, whether it is a class you write or a class you use from the Java platform API libraries." CS 307 Fundamentals of Computer ScienceImplementing Classes3– Sun code campClasses Are ...Another, simple definition:A class is a programmer defined data type.A data type is a set of possible values and the operations that can be performed on t e ope at o s t at ca be pe o ed othose valuesExample:Example: – single digit positive base 10 ints123456789–1, 2, 3, 4, 5, 6, 7, 8, 9– operations: add, subtractbl ?CS 307 Fundamentals of Computer ScienceImplementing Classes4–problems?Data TypesComputer Languages come with built in data typesIn Java, the primitive data types, native arraysMost computer languages provide a way for the ost co pute a guages p o de a ay o t eprogrammer to define their own data types–Java comes with a large library of classesJava comes with a large library of classesSo object oriented programming is a way of programming that is dominated by creating newprogramming that is dominated by creating new data types to solve a problem.We will look at how to create a new data typeCS 307 Fundamentals of Computer ScienceImplementing Classes5We will look at how to create a new data typeA Very Short and Incomplete History of Object OrientedHistory of Object Oriented Programming. (OOP)CS 307 Fundamentals of Computer ScienceImplementing Classes6OOP is not new.Si l 1 (19621965) d Si l 67Simula 1 (1962 -1965) and Simula 67 (1967) Norwegian Computing Center, Oslo, NbOlJh Dhl dKitNorway by Ole-Johan Dahl and Kristen Nygaard. Ti A dWi2001CS 307 Fundamentals of Computer ScienceImplementing Classes7Turing Award Winners -2001OOP LanguagesSmalltalk (1970s), Alan Kay's group at Xerox PARC C++ (early 1980s)Bjarne Stroustrup BellC++ (early 1980s), Bjarne Stroustrup, Bell LabsCS 307 Fundamentals of Computer ScienceImplementing Classes8OOP LanguagesMdl3Ob EifflJ C#Modula –3, Oberon, Eiffel, Java, C#, Python–many languages have some Object Oriented version or capabilityOne of the dominant styles for implementing complex programs with pgppglarge numbers of interacting componentsp– … but not the only programming paradigm and there are variations on object oriented iCS 307 Fundamentals of Computer ScienceImplementing Classes9programmingProgram Design in OOPOOP breaks up problems based on the data types found in the problem– as opposed to breaking up the problem based on the algorithms involvedGiven a problem statement, what thingsappear in the problem?The nouns of the problem are candidate classes.The actions and verbs of the problems are candidate methods of the classesCS 307 Fundamentals of Computer ScienceImplementing Classes10candidate methods of the classesShort Object Oriented Programming Design ExampleCS 307 Fundamentals of Computer ScienceImplementing Classes11Attendance Question 1The process of taking a large problem and breaking it up into smaller parts is known as:A. Functional programmingB. Object oriented programmingC Top down designC. Top down designD. Bottom up designEW fll hdE. Waterfall methodCS 307 Fundamentals of Computer ScienceImplementing Classes12MonopolyIf we had to start fhhfrom scratch what classes would weneed to create?need to create?CS 307 Fundamentals of Computer ScienceImplementing Classes13Individual Class DesignIndividual Class DesignCS 307 Fundamentals of Computer ScienceImplementing Classes14The Steps of Class DesignRequirementsRequirements– what is the problem to be solved–detailed requirements lead to specificationsdetailed requirements lead to specificationsNouns may be classesVerbs signal behavior and thus methods (alsoVerbs signal behavior and thus methods (also defines a classes responsibilities)walkthrough scenarios to find nouns and verbswalkthrough scenarios to find nouns and verbsimplementing and testing of classesdesign rather than implementation is normally thedesign rather than implementation is normally the hardest part–planning for reuseCS 307 Fundamentals of Computer ScienceImplementing Classes15pgClass DesignCl h ld bhiClasses should be cohesive.– They should be designed to do one thing well.Classes should be loosely coupled.– Changing the internal implementation details of a class should not affect other classes.– loose coupling can also be achieved within a class itselfCS 307 Fundamentals of Computer ScienceImplementing Classes16EncapsulationAl k i f dAlso know as separation of concerns and information hidingWh ti d t t ( l ) th d t ilWhen creating new data types (classes) the details of the actual data and the way operations work is hidden from the other programmers who will usehidden from the other programmers who will use those new data types–So they don't have to worry about themyy– So they can be changed without any ill effects (loose coupling)Encapsulation makes it easier to be able to use somethingidiidthJStilCS 307 Fundamentals of Computer ScienceImplementing Classes17–microwave, radio, ipod, the Java String classDesign to ImplementationDesign must me implemented using the syntax of the programming languageIn class example with a list of integersSlides include another example of creating a S des c ude a ot e e a p e o c eat g aclass to represent a playing dieCS 307 Fundamentals of Computer ScienceImplementing Classes18AListofintsA


View Full Document

UT CS 307 - Topic 5 Implementing Classes

Documents in this Course
Midterm 2

Midterm 2

15 pages

Midterm 1

Midterm 1

15 pages

Syllabus

Syllabus

24 pages

s

s

8 pages

Midterm 1

Midterm 1

14 pages

Midterm 2

Midterm 2

14 pages

Recursion

Recursion

14 pages

Midterm 1

Midterm 1

16 pages

Load more
Download Topic 5 Implementing Classes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Topic 5 Implementing Classes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Topic 5 Implementing Classes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?