collaborations and hierarchies
DESCRIPTION
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 PresentationTRANSCRIPT
![Page 1: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/1.jpg)
CS 4311 1
Collaborations and Hierarchies
CS 4311Chapters 5 and 6 of
Wirfs-Brock, R., Wilkerson, B., and Wiener, L., Designing Object-Oriented Software, Prentice Hall, 1990.
![Page 2: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/2.jpg)
2CS 4311
Outline
Collaborations Identifying collaborationsRecording collaborations
HierarchiesHierarchy graphsVenn diagrams
![Page 3: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/3.jpg)
3CS 4311
Motivation for Collaborations
Two ways to perform responsibilities??
Collaboration isRequest from one object to another in order to
fulfill a responsibility.
![Page 4: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/4.jpg)
4CS 4311
Motivation (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.
![Page 5: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/5.jpg)
5CS 4311
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?
![Page 6: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/6.jpg)
6CS 4311
Finding More Collaborations
Examine relationships between classes, especially:The “is-part-of” relationship, andThe “has-knowledge-of” relationship.
![Page 7: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/7.jpg)
7CS 4311
“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?
![Page 8: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/8.jpg)
8CS 4311
“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?
![Page 9: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/9.jpg)
9CS 4311
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.
Class: PersonResponsibilities CollaborationsKnows nameKnows address AddressBookKnows phone number PhoneBook…
Client
Server(or helper)
![Page 10: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/10.jpg)
10CS 4311
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
AddressBook1
PhoneBook2
![Page 11: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/11.jpg)
11CS 4311
Example: Mail-Order System
Class Responsibilities Collaborators
Catalog Create a catalogMail a catalog
Order Process an order Track an order
Product Ship a productPaymentSupplier Customer
![Page 12: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/12.jpg)
12CS 4311
Other Tools - UML
UML interaction diagramsMessage sequence diagramCommunication diagram (a.k.a. collaboration
diagram)
![Page 13: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/13.jpg)
13CS 4311
Message Sequence Diagram
: Customer : Order : Payment : Product : Supplier
place an order
process
validate
deliverif ( payment ok )
back order
if ( not in stock )
get address
mail to address
message
lifetimecontrol
object
![Page 14: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/14.jpg)
14CS 4311
Message Sequence Diagram
: Customer : Order : Payment : Product : Supplier
place an order
process
validate
deliverif ( payment ok )
back order
if ( not in stock )
get address
mail to address
Collaboration
![Page 15: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/15.jpg)
15CS 4311
Communication Diagram
p : Product
: Order : Payment
c : Customer
: Supplier
1.1 : ok := validate()
1.2 [ok] : deliver(c)
1.2.1 [not in stock] : back order(p)
1.2.2 : get address()
1 : place an order(c)
object
link
message
![Page 16: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/16.jpg)
16CS 4311
Communication Diagram
p : Product
: Order : Payment
c : Customer
: Supplier
1.1 : ok := validate()
1.2 [ok] : deliver(c)
1.2.1 [not in stock] : back order(p)
1.2.2 : get address()
1 : place an order(c)
Collaboration
![Page 17: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/17.jpg)
17CS 4311
Outline
Collaborations Hierarchies
Hierarchy graphVenn diagram
![Page 18: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/18.jpg)
18CS 4311
Review on CRC Process
1. Exploratory phase Identify a preliminary list of classes,
responsibilities and collaborations.
2. Analysis phase Obtain a more global understanding of
the design, e.g., by using tools such as:– Hierarchy graphs,– Venn diagrams, and– Contracts.
![Page 19: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/19.jpg)
19CS 4311
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.
![Page 20: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/20.jpg)
20CS 4311
Example
- Notation of [Wirfs-Brock-etal90] - Leaf nodes are often concrete classes.- Non-leaf nodes are often abstract classes.
PartTime FullTime
Employee
![Page 21: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/21.jpg)
21CS 4311
In UML …
Employee{abstract}
PartTime FullTime
Employee (or )
![Page 22: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/22.jpg)
22CS 4311
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.
![Page 23: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/23.jpg)
23CS 4311
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)?
![Page 24: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/24.jpg)
24CS 4311
Another Example of Hierarchy Graph
OrderedCollection
IndexableCollection
MagnitudeArray
Matrix String Date
![Page 25: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/25.jpg)
25CS 4311
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.
![Page 26: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/26.jpg)
26CS 4311
Example
PartTime FullTime
Employee
PartTime
set of responsibilities
Employee set of objects
PartTime FullTime
Employee
FullTime
![Page 27: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/27.jpg)
27CS 4311
Exercise
OrderedCollection
IndexableCollection
MagnitudeArray
Matrix String Date
Draw a Venn diagram for the following hierarchy graph.
![Page 28: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/28.jpg)
28CS 4311
In Sum, Hierarchies …
Are for reviewing the inheritance relationships, and
Use hierarchy graphs and Venn diagrams as a notation and an analysis tool
![Page 29: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/29.jpg)
29CS 4311
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.
![Page 30: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/30.jpg)
30CS 4311
Example – Using Venn Diagram To Check Hierarchy
A
B
If B supports only a part of responsibilities defined for A, whatdoes the Venn diagram look like? How to fix this?
![Page 31: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/31.jpg)
31CS 4311
Fixing the Problem
![Page 32: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/32.jpg)
32CS 4311
Example – Factoring Responsibilities
EllipseElement
TextElement
LineElement
RectangleElement
GroupElement
DrawingElement
![Page 33: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/33.jpg)
33CS 4311
Factoring (Cont.)
![Page 34: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/34.jpg)
34CS 4311
Factoring (Cont.)
![Page 35: Collaborations and Hierarchies](https://reader035.vdocuments.site/reader035/viewer/2022070420/56815da1550346895dcbcba7/html5/thumbnails/35.jpg)
35CS 4311
Group 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.