Skip to main content

8. Collaborations & Class Relationships

31/10/22

Collaborations

  • Represents a request form a client to a server client have responsibilities to perform.
    • Fulfil that responsibility by itself
  • Server provides services representing its responsibilities
    • Single collaboration is one-way from client to server
  • Doesn't mean information only flows in one direction
    • Each collaboration addresses one responsibility in server. Each helps to fulfil one responsibility of client - but, one client responsibility may need many collaborations

Patterns of class collaborations and relationships

Represent flow of control and information in system. Also defines the communication pattern Look for dependencies among responsibilities

For each responsibility of each class:

  1. Is class capable of fulfilling the responsibility itself?
  2. No? What does it need?
  3. From what classes can it acquire what it needs
  4. Shared responsibilities also define collaborations For each class:
  5. What does this class do or know?
  6. What other classes need these actions or information?

Composite vs. Container Objects

Composite objects

Object hierarchies

  • Each component has a different role to play in composite(responsible for parts)
  • Parts do not know about composite, but provide service to it
  • Composite collaborates with its components

Container objects

sets, arrays, lists, etc

  • Elements in a container are functionally identical; all serve same role
  • Containers may need to collaborate with their elements

Recording Collaborations

  • Write collaborating server classes.
  • If client responsibility needs 2 collaborations with same server class, write twice
  • If responsibility requires collaboration with another instance of same (or parent) class, include it