UML aggregation vs association

后端 未结 8 2368
無奈伤痛
無奈伤痛 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:39

    In UML aggregation is under-defined and since they haven't got any clearly defined semantic. A valid use-case of an aggregation is the encapsulation of a several classes, as stated in "Domain Driven Design" by Eric Evans.

    E.g. a car has four wheels. You might want to calculate the total amount of meters each wheel has driven, for each car. This calculation is done by the car-entity, since it knows which wheels it has and you don't care which wheels belong to which car.

    The car is the aggregation-root for all it's parts, like wheels, and you can't access the parts of a car from outside the aggregation, just the root.

    So basically an aggregation encapsulates a set of classes which belong to each other.

提交回复
热议问题