1 / 35

Collaborations and Hierarchies

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.

atara
Télécharger la présentation

Collaborations and Hierarchies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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.

  2. Outline • Collaborations • Identifying collaborations • Recording collaborations • Hierarchies • Hierarchy graphs • Venn diagrams

  3. Motivation for Collaborations • Two ways to perform responsibilities • ? • ? • Collaboration is • Request from one object to another in order to fulfill a responsibility.

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

  5. Finding Collaborations • Look 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?

  6. Finding More Collaborations • Examine relationships between classes, especially: • The “is-part-of” relationship, and • The “has-knowledge-of” relationship.

  7. “Is-part-of” Relationship • May imply responsibilities for maintaining information. • May fulfill responsibilities by delegating them. • Two of relationships: • Composite • Aggregate (or container) Q: Which relationship is more likely to require collaborations?

  8. “Has-knowledge-of” Relationship • May 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?

  9. Class: Person Responsibilities Collaborations Knows name Knows address AddressBook Knows phone number PhoneBook … Recording Collaborations • Write 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. Client Server (or helper)

  10. 1 2 AddressBook PhoneBook Collaboration Graph • Graphical representation of collaborations • Arrow from client to a “contract” of the server, denoted by a semicircle • Contract: group of responsibilities (more on this later) Person

  11. Class Responsibilities Collaborators Catalog Create a catalog Mail a catalog Order Process an order Track an order Product Ship a product Payment Supplier Customer Example: Mail-Order System

  12. Other Tools - UML • UML interaction diagrams • Sequence diagram • Communication diagram (a.k.a. collaboration diagram)

  13. object control lifetime message Sequence Diagram

  14. Collaboration Sequence Diagram

  15. object link message Communication Diagram

  16. Collaboration Communication Diagram

  17. Outline • Collaborations • Hierarchies • Hierarchy graph • Venn diagram

  18. Review of CRC Process • Exploratory phase • Identify a preliminary list of classes, responsibilities and collaborations. • Analysis phase • Obtain a more global understanding of the design, e.g., by using tools such as: • Hierarchy graphs, • Venn diagrams, and • Contracts.

  19. Hierarchy Graph • A 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.

  20. Employee PartTime FullTime Example - Notation of [Wirfs-Brock-etal90] - Leaf nodes are often concrete classes. - Non-leaf nodes are often abstract classes.

  21. Employee {abstract} Employee PartTime FullTime In UML … (or )

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

  23. Finding Abstract Classes • At 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)?

  24. Ordered Collection Indexable Collection Magnitude Matrix String Array Date Another Example of Hierarchy Graph

  25. Venn Diagram • Another 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.

  26. Employee PartTime FullTime set of objects Employee PartTime FullTime PartTime FullTime Example set of responsibilities Employee

  27. Ordered Collection Indexable Collection Magnitude Matrix String Array Date Exercise Draw a Venn diagram for the following hierarchy graph.

  28. In Sum, Hierarchies … • Are for reviewing the inheritance relationships, and • Use hierarchy graphs and Venn diagrams as a notation and an analysis tool

  29. Building Good Hierarchies • Model “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.

  30. Example – Using Venn Diagram To Check Hierarchy If B supports only a part of responsibilities defined for A, what does the Venn diagram look like? How to fix this? A B

  31. Fixing the Problem

  32. Rectangle Element Ellipse Element Text Element Line Element Group Element Drawing Element Example – Factoring Responsibilities

  33. Factoring (Cont.)

  34. Factoring (Cont.)

  35. Group Exercise • Suppose that you are designing a new Java compiler • and you identified the following concrete classes for • various 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.

More Related