collaborations and hierarchies

of 35 /35
CS 4311 1 Collaborations and Hierarchies CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object-Oriented Software, Prentice Hall, 1990.

Author: lali

Post on 12-Feb-2016




0 download

Embed Size (px)


Collaborations and Hierarchies. CS 4311 Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object-Oriented Software, Prentice Hall, 1990. Outline. Collaborations Identifying collaborations Recording collaborations Hierarchies Hierarchy graphs Venn diagrams. - PowerPoint PPT Presentation


  • CS 4311*Collaborations and HierarchiesCS 4311

    Chapters 5 and 6 of Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object-Oriented Software, Prentice Hall, 1990.


  • *CS 4311OutlineCollaborationsIdentifying collaborationsRecording collaborationsHierarchiesHierarchy graphsVenn diagrams

  • *CS 4311Motivation for CollaborationsTwo ways to perform responsibilities??Collaboration isRequest from one object to another in order to fulfill a responsibility.

  • *CS 4311Motivation (Cont.)Why identify collaborations?Collaborations represents flow of control and information through the system, May identify misplaced responsibilities, andMay identify missing responsibilities.In sum, shows dynamics of the system.

  • *CS 4311Finding CollaborationsLook at each responsibility of each class:Is the class capable of fulfilling this responsibility by itself?If not, where can it get what it needs?Look at each class:What other classes needs what this class does or knows?

  • *CS 4311Finding More CollaborationsExamine relationships between classes, especially:The is-part-of relationship, andThe has-knowledge-of relationship.

  • *CS 4311Is-part-of Relationship May imply responsibilities for maintaining information.May fulfill responsibilities by delegating them.Two of relationships:CompositeAggregate (or container)

    Q: Which relationship is more likely to require collaborations?

  • *CS 4311Has-knowledge-of RelationshipMay know other classes that are not in part-of relationships (i.e., associations in UML).May imply responsibilities to know information, and thus collaborations.

    Q: Can you think of an example?

  • *CS 4311Recording CollaborationsWrite the name of the server (or helper) class on the CRC card of the client.Write the name directly to the right of the responsibility the collaboration fulfills.ClientServer(or helper)

  • *CS 4311Collaboration GraphGraphical representation of collaborationsArrow from client to a contract of the server, denoted by a semicircleContract: group of responsibilities (more on this later)


  • *CS 4311Example: Mail-Order System

  • *CS 4311Other Tools - UMLUML interaction diagramsMessage sequence diagramCommunication diagram (a.k.a. collaboration diagram)

  • *CS 4311Message Sequence Diagram

  • *CS 4311Message Sequence Diagram

  • *CS 4311Communication Diagram

  • *CS 4311Communication Diagram

  • *CS 4311OutlineCollaborationsHierarchiesHierarchy graphVenn diagram

  • *CS 4311Review on CRC ProcessExploratory phaseIdentify a preliminary list of classes, responsibilities and collaborations.Analysis phaseObtain a more global understanding of the design, e.g., by using tools such as:Hierarchy graphs,Venn diagrams, andContracts.

  • *CS 4311Hierarchy GraphA graphical representation of inheritance between related classes.A hierarchy graph is a general tree.The nodes are classes and the arcs represent inheritance.Ancestor nodes are superclasses of descendent nodes, which are subclasses.

  • *CS 4311Example- Notation of [Wirfs-Brock-etal90] - Leaf nodes are often concrete classes.- Non-leaf nodes are often abstract classes.

  • *CS 4311In UML (or )

  • *CS 4311Abstract ClassesClasses that cannot be instantiated.Designed only to be inherited from, thus allowing reuse and avoiding duplication.Used to factor common behaviors among classes.

  • *CS 4311Finding Abstract ClassesAt the exploratory stage, all identified classes are probably concrete and some may have been identified as abstract.But, do you have all your abstract classes? That is, have you used the power of abstraction (factoring behavior)?

  • *CS 4311Another Example of Hierarchy Graph

  • *CS 4311Venn DiagramAnother tool to understand inheritance relationships.Views a class as a set of responsibilities.Thus, an intersection among classes: Denotes common responsibilities, and thus May indicates an abstract superclass.

  • *CS 4311Exampleset of responsibilitiesEmployee

  • *CS 4311ExerciseDraw a Venn diagram for the following hierarchy graph.

  • *CS 4311In Sum, Hierarchies Are for reviewing the inheritance relationships, andUse hierarchy graphs and Venn diagrams as a notation and an analysis tool

  • *CS 4311Building Good HierarchiesModel is-a relationships.Factor common responsibilities as high as possible.Make sure abstract classes do not inherit from concrete classes.Eliminate classes that do not add functionality.

  • *CS 4311Example Using Venn Diagram To Check HierarchyABIf B supports only a part of responsibilities defined for A, whatdoes the Venn diagram look like? How to fix this?

  • *CS 4311Fixing the Problem

  • *CS 4311Example Factoring Responsibilities

  • *CS 4311Factoring (Cont.)

  • *CS 4311Factoring (Cont.)

  • *CS 4311Group ExerciseSuppose that you are designing a new Java compilerand you identified the following concrete classes forvarious kinds of declarations allowed in Java.

    Class Declaration Interface Declaration Field Declaration Method Declaration Local Variable Declaration Method Parameter Declaration

    Organize the above classes into a class hierarchy.