每次写一次这个就要翻一次 PPT,这次干脆记录下来,便于以后查看。

聚合(aggregation)

聚合 是一种特殊的 联系

An Aggregation can be defined as:
A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts.

  • Aggregation is used to model a whole-part relationship between model elements. There are many examples of whole-part relationships: a Library contains Books, Departments are made up of Employees, a Computer is composed of a number of Devices. To model an aggregation, the aggregate (Department) has an aggregation association to its constituent parts (Employee).
  • A hollow diamond is attached to the end of an association path on the side of the aggregate (the whole) to indicate aggregation.
  • An aggregation relationship that has a multiplicity greater than one for the aggregate is called shared. Destroying the aggregate does not necessarily destroy the parts. By implication, a shared aggregation forms a graph or a tree with many roots. Shared aggregations are used when one instance is a part of two other instances. So, the same instance can participate in two different aggregations.

An aggregation is an “is a part-of” relationship.

UML 类图表示:一个整体可以拥有多个部分,一个部分属于一个整体:
UML 组合与聚合

组合

强语义的聚合,整体对象消失,部分对象也消失

UML 组合与聚合

相关文章: