Varun Setia
What are Composition, aggregation and association in OOPS?

Compare the differences between Composition, aggregation and association in OOPS.

By Varun Setia in .NET on Jul 27 2020
  • Ashwin Kumar
    Jan, 2021 20

    Inheritance: It is a relationship with a class and the relationship is IS-A
    example: Audi IS-A Car

    Association: It is a relationship with a class and the relationship is HAS-A
    examples:
    Employee HAS-A EmployerIDDetails
    Employee HAS-A ContactInformation

    Aggregation: It is a type of association. The relationship between the class is HAS-A. Existance of both the class does not depend on each other.
    example:
    Employee HAS-A ContactInformation

    if there is no Employee class still you can use ContactInformation class for other classes like Student, Customer etc

    Composition: It is a type of association. The relationship between the class is HAS-A. Existance of one of the class depend on the other.
    example:
    Employee HAS-A EmployerIDDetails

    if there is no Employee class then you cannot use EmployerIDDetails with any thing else

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS