Class Relationship Types in Object Oriented Programming | OOPS

Object-oriented programming involves understanding the relationships between the classes. The most common types of relationships are:
  • Collaboration (“uses a”): An object uses the features of another object to accomplish a task. For example, a Customer Repository “uses a” Customer object to populate on a Retrieve and serialize on a save.

  • Composition (“has a”): An object can be composed of other objects. For example, an Order “has a” customer, and an Order “has a” shipping address.

  • Aggregation: A special type of composition whereby the component parts do not exist except as part of the composition. For example, the Order and Order Item relationship is an aggregate because the Order Item does not exist except when it is associated with a specific Order.

  • Inheritance (“is a”): An object “is a” type of another object. For example, a Business Customer “is a” Customer, and a Residential Customer “is a” Customer.
These relationships define how the objects created from those classes can work together to perform the operations of the application.