What is the difference between association, aggregation and composition?

后端 未结 19 1837
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 01:44

What is the difference between association, aggregation, and composition? Please explain in terms of implementation.

19条回答
  •  隐瞒了意图╮
    2020-11-22 02:12

    https://www.linkedin.com/pulse/types-relationships-object-oriented-programming-oop-sarah-el-dawody/

    Composition: is a "part-of" relationship.

    for example “engine is part of the car”, “heart is part of the body”.

    Association: is a “has-a” type relationship

    For example, suppose we have two classes then these two classes are said to be “has-a” relationships if both of these entities share each other’s object for some work and at the same time they can exist without each other's dependency or both have their own lifetime.

    The above example showing an association relationship because of both Employee and Manager class using the object of each other and both their own independent life cycle.

    Aggregation: is based is on "has-a" relationship and it's is \\a special form of association

    for example, “Student” and “address”. Each student must have an address so the relationship between Student class and Address class will be “Has-A” type relationship but vice versa is not true.

提交回复
热议问题