Mark As Completed Discussion

Association

In object-oriented general software design, the relationship between one object's functionality and another's is known as an association. Note that an association between two objects is not the same thing as inheritance between two classes. Association means that one object uses another object or a function/method in that other object. In other words, association is defined as the relationship between objects when one object has one or more references to other objects.

Below are the core differences between association and inheritance:

  • Inheritance implies that two objects are the same type of object. One object just happens to be either a more generalized or more specific version of the other object. Association occurs between two different objects.

  • Inheritance is said to be an IS-A relationship whereas association is known as a HAS-A relationship.

  • The modality of inheritance depends on the programming language features. For example, Java does not support multiple inheritance, but C++ does. On the other hand, any language can have one-to-one, one-to-many, and many-to-many associations between objects.

There are two types of associations between objects: composition and aggregation. Let's understand what those are.