DOC PREVIEW
Yale CPSC 427 - Object-Oriented Programming
School name Yale University
Pages 13

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 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 13 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 13 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 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OutlineInteracting Classes and UML (cont.)Design Exercise: Family DatebookModel-Viewer-Controller ParadigmDemo: StopwatchOutline UML Datebook MVC StopwatchCPSC 427a: Object-Oriented ProgrammingMichael J. FischerLecture 12October 19, 2010CPSC 427a 1/13Outline UML Datebook MVC StopwatchInteracting Classes and UML (cont.)Design Exercise: Family DatebookModel-Viewer-Controller ParadigmDemo: StopwatchCPSC 427a 2/13Outline UML Datebook MVC StopwatchInteracting Classes and UML (cont.)CPSC 427a 3/13Outline UML Datebook MVC StopwatchAccessing B in A’s methodsAccess patterns:Iparameter, local variable, or return has type B/B&/B*Ia method in A accesses B’s data members: B::var or b.varIa method in A invokes B’s methods: B::func() or b.func()Iindirect: c.b.func()If A knows B only through parameter or local variables, we also saythat A uses B. The use relationship is generally considered to be aweak relationship.CPSC 427a 4/13Outline UML Datebook MVC Stopwatch“Law” of Consistency/EncapsulationRelation of B::var or b.var in A is typically not recommendedbecause it violates encapsulation and may lead to inconsistentstate.Why is the design below not desirable?class SpeedDataCollection{...// add a new data valuepublic void addValue(int speed);// return average speedpublic double averageSoFar;...};CPSC 427a 5/13Outline UML Datebook MVC Stopwatch“Law” of DemeterChaining such as c.b.func() is typically not recommended as itincreases coupling.For example, assume class A has a data member Dog* dog. Oneway to ask the dog object to move is dog->leg()->walk(). Butthis is less desirable than calling dog->walk().In OO design, this is called the “Law” of Demeter, also called“Law” of Least Knowledge:I“the method of a class should not depend on any way on thestructure of any class, except the immediate (top-level)structure of its own class.”This principle has other names such as Delegation and Do nottalk to Strangers.CPSC 427a 6/13Outline UML Datebook MVC Stopwatch“Law” of DemeterFormally, the “Law” of Demeter for functions requires that amethod M of an object A may only invoke the methods of thefollowing kinds of objects:IA itselfIM’s parametersIany objects created/instantiated within MIA’s direct component objectsIa global variable, accessible by A, in the scope of MOne can consider layered architecture of many systems (e.g., thelayered network architecture) as following this design guideline.CPSC 427a 7/13Outline UML Datebook MVC StopwatchDesign Exercise: Family DatebookCPSC 427a 8/13Outline UML Datebook MVC StopwatchDesign Exercise: FamilyDatebookRequirement: design a datebook that can be shared by a family,where each family member can have a list of app ointments, and anappointment may involve multiple family members.10032001April 27 9:15 Dr. MaApril 29 5:30 CS626May 3 6pm MaryWhat classes do we design and their relationships?CPSC 427a 9/13Outline UML Datebook MVC StopwatchModel-View-Controller ParadigmCPSC 427a 10/13Outline UML Datebook MVC StopwatchModel-Viewer-Controller design paradigmInteractive systems evolve over time.Model-Viewer-Controller is a design paradigm for addressing suchsystems.IThe model keeps the state of the evolving system.IThe viewer allows the state to be examined.IThe controller responds to external inputs and causes statechanges.Example: Airline reservation systemIDatabase keeps the state of reservations.IViewer show the empty seats.IController is the ticket agent.CPSC 427a 11/13Outline UML Datebook MVC StopwatchDemo: StopwatchCPSC 427a 12/13Outline UML Datebook MVC StopwatchRealtime measurementsStopWatch is a class for measuring realtime performance of code.It emulates a stopwatch with 3 buttons: reset, start, and stop.At any time, the watch displays the cumulative time that thestopwatch has been running.(See demo.)CPSC 427a


View Full Document

Yale CPSC 427 - Object-Oriented Programming

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