Skip to content

Instantly share code, notes, and snippets.

@Teebor-Choka
Created June 21, 2024 20:39
Show Gist options
  • Save Teebor-Choka/501b1adec5fe46f44b3447a3fa04f7a9 to your computer and use it in GitHub Desktop.
Save Teebor-Choka/501b1adec5fe46f44b3447a3fa04f7a9 to your computer and use it in GitHub Desktop.
Object Oriented Programming (OOP)

Object relationships

Association

(using relationship - "uses")

A - B or A -> B (A is associated with B)

  • weakest relationship (semantic dependency)
  • no ownership, separate life-times
  • allows one object instance to cause another to perform an action on its behalf
    • the causation is called "sending a message", "invoking a method" or "calling a member function" to the controlled object
  • navigation across an association is bidirectional
    • it may be limited to one direction by adorning some end with an arrowhead pointing to the direction of traversal
  • e.g. Manager & Access card

Aggregation

(special association - using relationship with "has")

A -<> B (A groups B)

  • objects have their own-life cycle, but an ownership exists
  • inbetween Association and Composition
  • e.g. Manager & Worker

Composition

(existence relationship "has a")

A -<:> B (A has B)

  • object composition (not to be confused with function composition) is a combines simple objects into more complex ones
  • life-time of both objects is bound together (owner dies with ownee and vice-versa)
  • e.g. Project & Manager

Dependency

(needs to know)

A ---> B (A needs to know about B)

  • something depends on a reference to something
  • e.g. Order & Customer

Generalization

(inheritance - "is a")

A -|> B (A specializes B, B is a generalization of A)

  • one object extends another one and inherits its interface and variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment