charlie garrod michael hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... ·...
TRANSCRIPT
![Page 1: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/1.jpg)
115-214
SchoolofComputerScience
PrinciplesofSoftwareConstruction:Objects,Design,andConcurrency
Designing(sub-)systems
Responsibilityassignment
CharlieGarrod MichaelHilton
![Page 2: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/2.jpg)
215-214
Administrivia
• ReadingforToday:• UMLandPatternsChapter14,15,and16
• MidtermexamnextThursday(September28th)– Examreviewsession:Hamerschlag HallB103Wed7-9pm– PracticeExampostedonPiazza
• MuddiestPointFeedback
![Page 3: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/3.jpg)
315-214
Homework4
• Threeparts,partAdueOct5th
• Designreviewmeetingnextweek
![Page 4: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/4.jpg)
415-214
REVIEW:Sequenceandcommunicationdiagrams
![Page 5: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/5.jpg)
515-214
Problem Space
Domain Model
SolutionSpace
Object Model
Our path toward a more formal design process
• Real-worldconcepts• Requirements,concepts• Relationshipsamongconcepts• Solvingaproblem• Buildingavocabulary
• Systemimplementation• Classes,objects• Referencesamongobjectsand
inheritancehierarchies• Computingaresult• Findingasolution
![Page 6: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/6.jpg)
615-214
Artifactsofourdesignprocess
• Model/diagramtheproblem,defineobjects– Domainmodel(a.k.a.conceptualmodel)✓
• Definesystembehaviors– Systemsequencediagram– Systembehavioralcontracts
• Assignobjectresponsibilities,defineinteractions– Objectinteractiondiagrams
• Model/diagramapotentialsolution– Objectmodel
Understandingtheproblem
Definingasolution
![Page 7: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/7.jpg)
715-214
Buildingadomainmodelforalibrarysystem
Apubliclibrary typicallystoresacollectionofbooks,movies,orotherlibraryitems availabletobeborrowedbypeoplelivinginacommunity.Eachlibrarymember typicallyhasalibraryaccount andalibrarycard withtheaccount’sIDnumber,whichshecanusetoidentifyherselftothelibrary.
Amember’slibraryaccountrecordswhichitemsthememberhasborrowedandtheduedate foreachborroweditem.Eachtypeofitemhasadefaultrentalperiod,whichdeterminestheitem’sduedatewhentheitemisborrowed.Ifamemberreturnsanitemaftertheitem’sduedate,thememberowesalatefeespecificforthatitem,anamountofmoneyrecordedinthemember’slibraryaccount.
![Page 8: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/8.jpg)
815-214
Onedomainmodelforthelibrarysystem
![Page 9: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/9.jpg)
915-214
Notesonthelibrarydomainmodel
• Allconceptsareaccessibletoanon-programmer• TheUMLissomewhatinformal
– Relationshipsareoftendescribedwithwords
• Real-world"is-a"relationshipsareappropriateforadomainmodel• Real-wordabstractionsareappropriateforadomainmodel• Iterationisimportant
– Thisexampleisafirstdraft.Someterms(e.g.Itemvs.LibraryItem,Accountvs.LibraryAccount)wouldlikelyberevisedinarealdesign.
• Aggregatetypesareusuallymodeledasclasses• Primitivetypes(numbers,strings)areusuallymodeledasattributes
![Page 10: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/10.jpg)
1015-214
BuildadomainmodelforMonopoly
![Page 11: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/11.jpg)
1115-214
BuildadomainmodelforMonopoly
Monopolyisagameinwhicheachplayerhasapiecethatmovesaroundagameboard,withthepiece’schangeinlocationdeterminedbyrollingapairofdice.Thegameboardconsistsofasetofproperties(initiallyownedbyabank)thatmaybepurchasedbytheplayers.
Whenapiecelandsonapropertythatisnotowned,theplayermayusemoneytobuythepropertyfromthebankforthatproperty’sprice.Ifaplayerlandsonapropertyshealreadyowns,shemaybuildhousesandhotelsontheproperty;eachhouseandhotelcostssomepricespecificfortheproperty.Whenaplayer’spiecelandsonapropertyownedbyanotherplayer,theownercollectsmoney(rent)fromtheplayerwhosepiecelandedontheproperty;therentdependsonthenumberofhousesandhotelsbuiltontheproperty.
Thegameisplayeduntilonlyoneremainingplayerhasmoneyandproperty,withalltheotherplayersbeingbankrupt.
![Page 12: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/12.jpg)
1215-214
Understandingsystembehaviorwithsequencediagrams
• Asystemsequencediagram isamodelthatshows,foronescenarioofuse,thesequenceofeventsthatoccuronthesystem’sboundary
• Designgoal:Identifyanddefinetheinterfaceofthesystem– Twocomponents:Auserandtheoverallsystem
![Page 13: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/13.jpg)
1315-214
Understandingsystembehaviorwithsequencediagrams
• Asystemsequencediagram isamodelthatshows,foronescenarioofuse,thesequenceofeventsthatoccuronthesystem’sboundary
• Designgoal:Identifyanddefinetheinterfaceofthesystem– Twocomponents:Auserandtheoverallsystem
• Input:Domaindescriptionandoneusecase• Output:Asequencediagramofsystem-leveloperations
– Includeonlydomain-levelconceptsandoperations
![Page 14: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/14.jpg)
1415-214
Onesequencediagramforthelibrarysystem
Usecasescenario:Alibrarymembershouldbeabletouseherlibrarycardtologinatalibrarysystemkioskandborrowabook.Afterconfirmingthatthememberhasnounpaidlatefees,thelibrarysystemshoulddeterminethebook’sduedatebyaddingitsrentalperiodtothecurrentday,andrecordthebookanditsduedateasaborrowediteminthemember’slibraryaccount.
![Page 15: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/15.jpg)
1515-214
Onesequencediagramforthelibrarysystem
Usecasescenario:Alibrarymembershouldbeabletouseherlibrarycardtologinatalibrarysystemkioskandborrowabook.Afterconfirmingthatthememberhasnounpaidlatefees,thelibrarysystemshoulddeterminethebook’sduedatebyaddingitsrentalperiodtothecurrentday,andrecordthebookanditsduedateasaborrowediteminthemember’slibraryaccount.
![Page 16: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/16.jpg)
1615-214
BuildonesystemsequencediagramforMonopoly
Usecasescenario:Whenaplayerlandsonanunownedpropertyandhasenoughmoneytobuytheproperty,sheshouldbeabletobuythepropertyfortheproperty’sprice.Thepropertyshouldnolongerbepurchasablefromthebankbyotherplayers,andmoneyshouldbemovedfromtheplayertothebank.
![Page 17: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/17.jpg)
1715-214
Formalizesystembehaviorwithbehavioralcontracts
• Asystembehavioralcontract describesthepre-conditionsandpost-conditionsforsomeoperationidentifiedinthesystemsequencediagrams– System-leveltextualspecifications,likesoftwarespecifications
![Page 18: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/18.jpg)
1815-214
Asystembehavioralcontractforthelibrarysystem
Operation: borrow(item)
Pre-conditions: Librarymemberhasalreadyloggedintothesystem.Itemisnotcurrentlyborrowedbyanothermember.
Post-conditions: Logged-inmember'saccountrecordsthenewly-borroweditem,orthememberiswarnedshehasanoutstandinglatefee.Thenewly-borroweditemcontainsafutureduedate,computedastheitem'srentalperiodplusthecurrentdate.
![Page 19: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/19.jpg)
1915-214
AsystembehavioralcontractforMonopoly
Operation: buy(property)
Pre-conditions: ?
Post-conditions: ?
![Page 20: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/20.jpg)
2015-214
Distinguishingdomainvs.implementationconcepts
• Domain-levelconcepts:– Almostanythingwithareal-worldanalogue
• Implementation-levelconcepts:– Implementation-likemethodnames– Programmingtypes– Visibilitymodifiers– Helpermethodsorclasses– Artifactsofdesignpatterns
![Page 21: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/21.jpg)
2115-214
Summary:Understandingtheproblemdomain
• Knowyourtoolstobuilddomain-levelrepresentations– Domainmodels– Systemsequencediagrams– Systembehavioralcontracts
• Befastand(sometimes)loose– Elideobvious(?)details– Iterate,iterate,iterate,…
• Getfeedbackfromdomainexperts– Useonlydomain-levelconcepts
![Page 22: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/22.jpg)
2215-214
Artifactsofourdesignprocess
• Model/diagramtheproblem,defineobjects– Domainmodel(a.k.a.conceptualmodel)✓
• Definesystembehaviors– Systemsequencediagram✓– Systembehavioralcontracts✓
• Assignobjectresponsibilities,defineinteractions– Objectinteractiondiagrams
• Model/diagramapotentialsolution– Objectmodel
Understandingtheproblem
Definingasolution
![Page 23: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/23.jpg)
2315-214
Object-orientedprogramming
• Programmingbasedonstructuresthatcontainbothdataandmethodspublic class Bicycle {private int speed;private final Wheel frontWheel, rearWheel;private final Seat seat;…
public Bicycle(…) { … }
public void accelerate() { speed++;
}
public int speed() { return speed; }}
![Page 24: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/24.jpg)
2415-214
Object-OrientedDesign
• Object-OrientedDesign:“Afteridentifyingyourrequirementsandcreatingadomainmodel,thenaddmethodstothesoftwareclasses,anddefinethemessagingbetweentheobjectstofulfilltherequirements.”
• Buthow?– Howshouldconceptsbeimplementedbyclasses?– Whatmethodbelongswhere?– Howshouldtheobjectsinteract?– Thisisacritical,important,andnon-trivialtask
![Page 25: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/25.jpg)
2515-214
Responsibilityinobject-orientedprogramming
• Data:– Privateorotherwiseencapsulateddata– Dataincloselyrelatedobjects
• Methods:– Privateorotherwiseencapsulatedoperations– Objectcreation,ofitselforotherobjects– Initiatingactionsinotherobjects– Coordinatingactivitiesamongobjects
![Page 26: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/26.jpg)
2615-214
Responsibilities
• Responsibilitiesarerelatedtotheobligationsofanobjectintermsofitsbehavior.
• Twotypesofresponsibilities:– knowing– doing
• Doingresponsibilitiesofanobjectinclude:– doingsomethingitself,suchascreatinganobjectordoingacalculation– initiatingactioninotherobjects– controllingandcoordinatingactivitiesinotherobjects
• Knowingresponsibilitiesofanobjectinclude:– knowingaboutprivateencapsulateddata– knowingaboutrelatedobjects– knowingaboutthingsitcanderiveorcalculate
![Page 27: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/27.jpg)
2715-214
Usinginteractiondiagramstoassignobjectresponsibility
• Foragivensystem-leveloperation,createanobjectinteractiondiagramattheimplementation-level ofabstraction– Implementation-levelconcepts:
• Implementation-likemethodnames• Programmingtypes• Helpermethodsorclasses• Artifactsofdesignpatterns
![Page 28: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/28.jpg)
2815-214
Exampleinteractiondiagram#1
Usecasescenario:Alibrarymembershouldbeabletouseherlibrarycardtologinatalibrarysystemkioskand…
![Page 29: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/29.jpg)
2915-214
Exampleinteractiondiagram#2
Usecasescenario:…andborrowabook.Afterconfirmingthatthememberhasnounpaidlatefees,thelibrarysystemshoulddeterminethebook’sduedatebyaddingitsloanperiodtothecurrentday,andrecordthebookanditsduedateasaborrowediteminthemember’slibraryaccount.
![Page 30: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/30.jpg)
3015-214
Interactiondiagramshelpevaluatedesignalternatives
Createtwopossibleinteractiondiagrams:1. Solvingacryptarithm,assumingthatthecryptarithm classhas
responsibilityforsolvingitself2. Solvingacryptarithm,assumingthatthemainmethod(oradelegated
methodorclass)hasresponsibilityforsolvingthecryptarithm
![Page 31: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/31.jpg)
3115-214
Goals,Principles,Guidelines
• DesignGoals– Desiredqualityattributesofsoftware– Drivenbycost/benefiteconomics– Examples:designforchange,understanding,reuse,…
• DesignPrinciples– Guidelinesfordesigningsoftware– Supportoneormoredesigngoals– Examples:Informationhiding,lowrepr.gap,lowcoupling,highcohesion,…
• DesignHeuristics– Rulesofthumbforlow-level designdecisions– Promotedesignprinciples,andultimatelydesigngoals– Example:Creator,Expert,Controller
• DesignPatterns– Generalsolutionstorecurringdesignproblems– Promotedesigngoals,butmayaddcomplexityorinvolvetradeoffs– Examples:Decorator,Strategy,TemplateMethod
• Goals,principles,heuristics,patternsmayconflict– Usehigh-levelgoalsofprojecttoresolve
Goals
Heuristics Patterns
Principles
X
![Page 32: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/32.jpg)
3215-214
Heuristicsforresponsibilityassignment
• Controllerheuristic• Informationexpertheuristic• Creatorheuristic
Goals
Heuristics Patterns
Principles
![Page 33: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/33.jpg)
3315-214
Thecontrollerheuristic
• Assignresponsibilityforallsystem-levelbehaviorstoasinglesystem-levelobjectthatcoordinatesanddelegatesworktootherobjects– Alsoconsiderspecificsub-controllersforcomplexuse-casescenarios
• Designprocess:Extractinterfacefromsystemsequencediagrams– Keyprinciples:Lowrepresentationalgapandhighcohesion
![Page 34: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/34.jpg)
3415-214
Informationexpertheuristic
• Assignresponsibilitytotheclassthathastheinformationneededtofulfilltheresponsibility– Initialization,transformation,andviewsofprivatedata– Creationofcloselyrelatedorderivedobjects
![Page 35: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/35.jpg)
3515-214
Responsibilityinobject-orientedprogramming
• Data:– Privateorotherwiseencapsulateddata– Dataincloselyrelatedobjects
• Methods:– Privateorotherwiseencapsulatedoperations– Objectcreation,ofitselforotherobjects– Initiatingactionsinotherobjects– Coordinatingactivitiesamongobjects
![Page 36: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/36.jpg)
3615-214
Informationexpertheuristic
• Assignresponsibilitytotheclassthathastheinformationneededtofulfilltheresponsibility– Initialization,transformation,andviewsofprivatedata– Creationofcloselyrelatedorderivedobjects
• Designprocess:Assignmentfromdomainmodel– Keyprinciples:Lowrepresentationalgapandlowcoupling
![Page 37: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/37.jpg)
3715-214
Usetheinformationexpertheuristic
• InHomework3,whatobjectshouldhavetheresponsibilitytosolveacryptarithm?
• Whatistherelevantinformation?
![Page 38: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/38.jpg)
3815-214
Usetheinformationexpertheuristic
• InHomework3,whatobjectshouldhavetheresponsibilitytosolveacryptarithm?
• Whatistherelevantinformation?– Whoknowsthe#ofdigits(e.g.base10)inthecryptarithm?– Whoknowsthelettersofthecryptarithm?– Whocanevaluatethecryptarithm expressionstocheckforequality?
![Page 39: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/39.jpg)
3915-214
Anotherdesignprinciple:Minimizeconceptualweight
• Labeltheconceptsforaproposedobject– Relatedtorepresentationalgapandcohesion
![Page 40: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/40.jpg)
4015-214
Creatorheuristic:WhocreatesanobjectFoo?
• AssignresponsibilityofcreatinganobjectFootoaclassthat:– HasthedatanecessaryforinitializinginstancesofFoo– Contains,aggregates,orrecordsinstancesofFoo– CloselyusesormanipulatesinstancesofFoo
• Designprocess:Extractfromdomainmodel,interactiondiagrams– Keyprinciples:Lowcouplingandlowrepresentationalgap
![Page 41: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/41.jpg)
4115-214
Usethecreatorheuristic
• InHomework3,whatobjectshouldhavetheresponsibilityforcreatingthepermutationgenerator?
![Page 42: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/42.jpg)
4215-214
Object-levelartifactsofthisdesignprocess
• Objectinteractiondiagrams addmethodstoobjects– Caninferadditionaldataresponsibilities– Caninferadditionaldatatypesandarchitecturalpatterns
• Objectmodel aggregatesimportantdesigndecisions– Isanimplementationguide
![Page 43: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/43.jpg)
4315-214
Creatinganobjectmodel
• Extractdata,methodnames,andtypesfrominteractiondiagrams– Includeimplementationdetailssuchasvisibilities
![Page 44: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/44.jpg)
4415-214
![Page 45: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/45.jpg)
4515-214
Createanobjectmodelforyourcryptarithm solver
![Page 46: Charlie Garrod Michael Hilton - cs.cmu.educharlie/courses/15-214/2017-fall/slides/20170926... · 26/09/2017 · Solving a cryptarithm, assuming that the cryptarithmclass has responsibility](https://reader033.vdocuments.net/reader033/viewer/2022060808/608cfab09c8a6b1e380d5af0/html5/thumbnails/46.jpg)
4615-214
Summary:
• Object-levelinteractiondiagramsandobjectmodelsystematicallyguidethedesignprocess– Convertdomainmodel,systemsequencediagram,andcontractsto
object-levelresponsibilities
• Useheuristicstoguide,butnotdefine,designdecisions• Iterate,iterate,iterate…