What is the difference between association, aggregation and composition?

后端 未结 19 2377
伪装坚强ぢ
伪装坚强ぢ 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:02

    I think this link will do your homework: http://ootips.org/uml-hasa.html

    To understand the terms I remember an example in my early programming days:

    If you have a 'chess board' object that contains 'box' objects that is composition because if the 'chess board' is deleted there is no reason for the boxes to exist anymore.

    If you have a 'square' object that have a 'color' object and the square gets deleted the 'color' object may still exist, that is aggregation

    Both of them are associations, the main difference is conceptual

提交回复
热议问题