UML aggregation vs association

后端 未结 8 2332
無奈伤痛
無奈伤痛 2020-11-28 04:48

Here I am, with another question about aggregation and association. I wanted to learn some basics of UML, so I started reading \"UML distilled\" by Martin Fowler. I read bot

相关标签:
8条回答
  • 2020-11-28 05:41

    To add, I would just suggest to download UML specification from OMG site : best reference and see p 110.

    none Indicates that the Property has no aggregation semantics.

    shared Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.

    composite Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility for the existence and storage of the composed objects (see the definition of parts in 11.2.3).

    0 讨论(0)
  • 2020-11-28 05:45

    Maybe this can help you, but i don't think you will find the perfect explanation :

    The difference is one of implication. Aggregation denotes whole/part relationships whereas associations do not. However, there is not likely to be much difference in the way that the two relationships are implemented. That is, it would be very difficult to look at the code and determine whether a particular relationship ought to be aggregation or association. For this reason, it is pretty safe to ignore the aggregation relationship altogether.
    [Robert C. Martin | UML]

    And an example for each situation :

    a) Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with a single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently.

    b) Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child object can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department, the teacher object will not be destroyed. We can think about “has-a” relationship.
    [Maesh | GeeksWithBlogs]

    0 讨论(0)
提交回复
热议问题