What is the difference between Composition and Association relationship?

前端 未结 8 1988
眼角桃花
眼角桃花 2020-12-01 04:05

In OOP, what is the difference between composition (denoted by filled diamond in UML) and association (denoted by empty diamond in UML) relationship between classes. I\'m a

8条回答
  •  没有蜡笔的小新
    2020-12-01 04:20

    Independent existence.

    An Invoice is composed of line items.

    What's a line item that's not on an invoice? It's -- well -- it's nothing. It can't exist independently.

    On the other hand, an Invoice is associated with a Customer.

    Customer has an independent existence, with or without an invoice.

    If the two things have independent existence, they may be associated.

    If one thing cannot exist independently, then it is part of a composition.

提交回复
热议问题