DOC PREVIEW
UMD CMSC 132 - Object-Oriented Design II

This preview shows page 1-2-23-24 out of 24 pages.

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

Unformatted text preview:

CMSC 132: Object-Oriented Programming IIObject-Oriented Design IIDepartment of Computer ScienceUniversity of Maryland, College ParkOverviewObject-oriented designObjects, methods⇒⇒⇒⇒Last lectureClasses, inheritance⇒⇒⇒⇒This lectureApplying object-oriented designElements 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 objectsClasses PropertiesClasses provides classification for objectsEvery object belongs to some classObjects ⇒⇒⇒⇒instances (instantiations) of a classExample ClassGiven a class CarObjects can includeMyHonda, YourHondaHerMiniCooperHisSUVAll Car objectsShare same properties & behaviorMay have different values for propertiesCarInheritance 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 transportationInheritance 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 thermostatForms of Inheritance SpecificationDefines behavior implemented only in subclassGuarantees subclasses implement same behaviorIn Java →abstract method in superclassSpecializationSubclass is customizedStill satisfies all requirements for parent classIn Java →override methodSpecialization ExampleForms of Inheritance ExtensionAdds new functionality to subclassIn Java →new methodLimitationRestricts behavior of subclassIn Java →override method, throw exceptionCombinationInherits features from multiple superclassesAlso called multiple inheritanceNot possible in JavaIn Java →implement interface insteadMultiple Inheritance Example CombinationAlarmClockRadio has two parent classesState & behavior from both Radio & AlarmClockSuperclassesApplying 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 settingHeaterTemperatureRoomFinding 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 SettingRoomTempFinding 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 VerbsUsesControlMaintainFinding 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()Example MessagesRoomThermostatHeaterGetTemperature()TurnOn() TurnOff()SetDesiredTemp()Resulting ClassesThermostatState – DialSettingMethods – SetDesiredTemp()HeaterState – HeaterOnMethods – TurnOn(), TurnOff()RoomState – TempMethods –


View Full Document

UMD CMSC 132 - Object-Oriented Design II

Documents in this Course
Notes

Notes

8 pages

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
Download Object-Oriented Design II
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 II 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 II 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?