1
Reply

What are Composition, aggregation and association in OOPS?

Varun Setia

Varun Setia

4y
1.8k
1
Reply

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

    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