Object-oriented designGoals of OO analysis (quick review)Goals of OO designFour activities of design (Coad)How does this design illustrate the separation of concerns principle?Four activities of design (continued)Reworking the class diagramReworking the class diagram (continued)Classes as active state machinesClasses as active state machines (cont.)Key idea for OOD: data structures can be activeCase Study: Full‑Screen Entry SystemsState diagrams in UMLSuper-statesUML package diagramsDesign process proceduresObject-oriented designCSE 432: Object-Oriented Software EngineeringGoals of OO analysis (quick review)What are the two main goals of OO analysis?1) Understand the customer’s requirements2) Describe problem domain as a set of classes and relationshipsWhat techniques have we studied for the 1st goal?Develop a requirements specificationDescribe scenarios of use in user’s language as use casesWhat techniques have we studied for the 2nd goal?CRC cards discover classes and run simulationsUML class diagrams represent classes & relationshipsSequence diagrams model dynamic behavior of a systemGoals of OO designOO design develops the analysis into a blueprint of a solutionWhere does the “blueprint” metaphor come from?OO design starts by fleshing the class diagramsCoad & Nicola call this "the continuum of representation principle: use a single underlying representation, from problem domain to OOA to OOD to OOP," i.e., class diagrams Reworks and adds detail to class diagrams, e.g., attribute types, visibility (public/private), additional constraints Looks for opportunities for reuse Addresses performance issues, both for system and usersDesigns UI, database, networking, as neededDesigns ADT to describe the semantics of classes in more detail Develops unit test plans based on class diagrams and ADT designFour activities of design (Coad)1) Improve domain analysis: reuse and performance OOA focuses primarily on the describing problem domain itselfOOD reexamines the domain with an eye to practical concerns Reuse: factor out common code in abstract classesPerformance tradeoffs: efficiency vs. effectiveness2) Human interaction: encapsulates user interfaceHIC knows how to present data, not how to compute itSeparation of concerns principle: Keep problem domain classes distinct from human interaction classes. Why?Loose coupling facilitates software reuse and maintenanceAn example: the Smalltalk Model-View-Controller framework: model is the problem domainview is the human interface (windows that view the problem domain objects)controller is the mouse or keyboard input, also interacting with P.D. objectsC++ Interviews is two part framework: subject (problem domain) & views (UI)How does this design illustratethe separation of concerns principle?Four activities of design (continued)3) Task managementMulti‑tasking and concurrency considerationsHow does separation of concerns apply here?Examples?4) Data managementStorage and retrieval of external dataDatabase design (relational or object-oriented)Or database interface (JDBC, CORBA)How does separation of concerns apply here?Reworking the class diagramAdd new relations implied in classesInverse operations (e.g., undo/redo, getData/setData)Factor complex behaviors out as classes themselvesIf only difference between subclasses is presentation of data, use a serviceShould we derive HexCount, BinaryCount, OctCount from Count?Rather, add a service, asBase, to present data in different basesDistinguish client (has-a) and inheritance (is-a) relationsMisuse of multiple inheritance is when a derived class is "composed of" several parent classesI.e., class AIRPLANE has parents WINGS, ENGINE, TAIL) But the behavior of AIRPLANE is not just the sum of its partsBjarne Stroustrup's heuristic: "can it have two?" Then it's a containment, or has-a relationReworking the class diagram (continued)Heuristic: use inheritance to extend existing classesE.g., ComplexMatrix adapts Array or OrderedCltnBut avoid adapting parents for the sake of their heirs (open‑closed principle)Generalize common behaviors in abstract classesE.g., Mouse, Tablet and Keyboard can all inherit behavior from an abstract class, InputDevice Use multiple inheritance for compound classesTeachingAssistant inherits from both Instructor and StudentWindow as a compound of Rectangle (graphical behaviors) and Tree (hierarchical behaviors)Note: many OO languages don’t support multiple inh.Classes as active state machinesConsider whether a class should keep track of its own internal stateExample from Bertrand Meyer: first cut design of LINKED_LIST classclass LINKABLE[T] ‑‑linkable cells feature value:T; right: LINKABLE[T]; ‑‑next cell ‑‑routines to change_value, change_right end; class LINKEDLIST[T] feature nb_elements: INTEGER; first_element: LINKABLE[T]; value(i:INTEGER):T is ‑‑value of i‑th element; loop until it reaches the ith element insert(i:INTEGER; val:T); ‑‑loop until it reaches ith element, then insert val delete(i:INTEGER); ‑‑loop until it reaches ith element, then delete itProblems with first‑cut?Getting the loops right is tricky (loops are error‑prone)Redundancy: the same loop logic recurs in all these routinesReuse leads to inefficiency: suppose I want a routine searchFind an element then replace it: I'll do the loop twice!Need some way to keep track of the position I found!Could return the LINKABLE cell found, but this would ruin encapsulationClasses as active state machines (cont.)Instead, view LINKED_LIST as a machine with an internal stateInternal state is information stored as attributes of an objectWhat have we added to represent internal state?Cursor: current position in the listsearch(item) routine moves the cursor until it finds iteminsert and delete operate on the element pointed at by cursorHow does this simplify the code of insert, delete, etc.?Client has a new view of LINKED_LIST objects: l.search(item); ‑‑find item in l if not offright then delete end; ‑‑delete LINKABLE at cursorOther routines move cursor: l.back; l.forthKey idea for OOD: data structures can be activeActive structures have internal states, which changeRoutines manipulate the
View Full Document