New version page

UMD CMSC 132 - Object-Oriented Design 2

Documents in this Course
Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Upgrade to remove ads

This preview shows page 1-2-3-4 out of 12 pages.

Save
View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

1Object-Oriented Design 2Nelson Padua-PerezChau-Wen TsengDepartment of Computer ScienceUniversity of Maryland, College ParkOverviewObject-oriented designObjects, methods ⇒ Last lectureClasses, inheritance ⇒ This lectureApplying object-oriented design2Elements of Object-Oriented DesignObjectsEntities in programMethodsFunctions associated with objectsClassesGroups of objects with similar propertiesInheritanceRelationship between classesClasses DefinitionGroup of objects with same state & behaviorAbstract description of a group of objectsSimilar to data typesType is a set of data values & their operationsExample ⇒ integer, real, boolean, stringCan view classes as types for objects3Classes PropertiesClasses provides classification for objectsEvery object belongs to some classObjects ⇒ instances (instantiations) of a classExample ClassGiven a class CarObjects can includeMyHonda, YourHonda,HerMiniCooper, HisSUVAll Car objectsShare same properties & behaviorMay have different values for propertiesCar4Inheritance DefinitionRelationship between classes when state and behavior of one class is a subset of another classTerminologySuperclass / parent ⇒ More general classSubclass ⇒ More specialized classSuperclassSubclassInheritancePropertiesSubclass inherits state & behavior of superclass“Is-a” relationship exists between inherited classesExample – train is a type of transportation5Inheritance Inheritance forms a hierarchyHelps organize classesInheritance is transitiveClass inherits state & behavior from all ancestorsInheritance promotes code reuseReuse state & behavior for classInheritance Hierarchy ExampleClassesThermostatAnalog thermostatDigital thermostatProgrammable thermostat6Forms of Inheritance SpecificationDefines behavior implemented only in subclassGuarantees subclasses implement same behaviorSpecializationSubclass is customizedStill satisfies all requirements for parent classSpecialization Example7Forms of Inheritance ExtensionAdds new functionality to subclassLimitationRestricts behavior of subclassCombinationInherits features from multiple superclassesAlso called multiple inheritanceNot possible in JavaMultiple Inheritance Example CombinationAlarmClockRadio has two parent classesState & behavior from both Radio & AlarmClockSuperclasses8Applying Object-Oriented Design 1. Look at objects participating in systemFind nouns in problem statement (requirements & specifications)Noun may represent class needed in design2. Look at interactions between objectsFind verbs in problem statementVerb may represent message between objects3. Design classes accordinglyDetermine relationship between classesFind state & methods needed for each class1) Finding ClassesThermostat uses dial setting to control a heaterto maintain constant temperature in roomNounsThermostatDial settingHeaterTemperatureRoom9Finding ClassesAnalyze each nounDoes noun represent class needed in design?Noun may be outside systemNoun may describe state in classAnalyzing NounsThermostatCentral class in modelDial settingState in class (Thermostat)HeaterClass in modelRoomClass in modelTemperatureState in class (Room)HeaterThermostatDial SettingRoomTemp10Finding ClassesDecision not always clearPossible to make everything its own classApproach taken in SmalltalkOverly complex2+3 = 5 vs. NUM2.add(NUM3) = NUM5Impact of designMore classes ⇒ more abstraction, flexibilityFewer classes ⇒ less complexity, overheadChoice (somewhat) depends on personal preferenceAvoid making functions into classesExamples – class ListSorter, NameFinder2) Finding MessagesThermostat uses dial setting to control a heater to maintain constant temperature in room VerbsUsesControlMaintain11Finding MessagesAnalyze each verbDoes verb represent interaction between objects? For each interactionAssign methods to classes to perform interactionAnalyzing VerbsUses“Thermostat uses dial setting…”⇒ Thermostat.SetDesiredTemp()Control“to control a heater…”⇒ Heater.TurnOn()⇒ Heater.TurnOff()Maintain“to maintain constant temperature in room”⇒ Room.GetTemperature()12Example MessagesRoomThermostatHeaterGetTemperature()TurnOn() TurnOff()SetDesiredTemp()Resulting ClassesThermostatState – DialSettingMethods – SetDesiredTemp()HeaterState – HeaterOnMethods – TurnOn(), TurnOff()RoomState – TempMethods –


View Full Document
Download Object-Oriented Design 2
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 Object-Oriented Design 2 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 Object-Oriented Design 2 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?