UML Class and Object Diagrams Overview

Class diagram is UML structure diagram which shows structure of the designed system at the level of classes and interfaces, shows their features, constraints and relationships - associations, generalizations, dependencies, etc.
Some common types of class diagrams are:

Object diagram could be considered as instance level class diagram which shows instance specifications of classes and interfaces (objects), slots with value specifications, and links (instances of association).

Domain Model Diagram

image.png
Domain diagram overview - classes, interfaces, associations, usage, realization, multiplicity.

Diagram of Implementation Classes

image.png
Elements of implementation class diagram - classes, interfaces, associations, usage, realization.

Object Diagram

Object diagram was defined in now obsolete UML 1.4.2 Specification as “a graph of instances, including objects and data values. A static object diagram is an instance of a class diagram; it shows a snapshot of the detailed state of a system at a point in time.” _It also stated that object diagram is “a class diagram with objects and no classes.”
UML 2.4 specification simply provides no definition of object diagram except that
“the following nodes and edges are typically drawn in an object diagram: Instance Specification and Link (i.e., Association).”
Note, that UML 2.5 standard hierarchy of diagrams (see UML 2.5 diagrams overview), shows class diagrams and object diagrams as completely unrelated. Some other authoritative UML sources state that component diagrams and deployment diagrams containing only instance specifications are also special kinds of object diagrams.
Object diagram overview below shows some major elements of object diagram - named and anonymous instance specifications for objects, slots with value specifications, and links (instances of association).
图::类 Class - 图3
_Object diagram overview - instance specifications, value specifications, slots, and links.

https://www.uml-diagrams.org/class-diagrams-overview.html

参考:
https://www.cnblogs.com/gaochundong/p/uml_association_aggregation_composition.html

元素名称 符号图例 含义
Association 图::类 Class - 图4 A 和 B 相互调用和访问对方的元素。
A and B call and access each other’s elements.
Aggregation 图::类 Class - 图5 A 中拥有一个 B,但 B 脱离于 A 仍然可以独立存活。
A has a B, and B can outlive A.
A “uses” B = Aggregation : B exists independently (conceptually) from A.
Composition 图::类 Class - 图6 A 中拥有一个 B,B 脱离 A 后在系统中没有任何存活的意义。
A has a B, and B depends on A.
A “owns” B = Composition : B has no meaning or purpose in the system without A.

我们可以从不同的角度来理解和区分这三种关系:

**
Association Aggregation Composition
Owner No owner Single owner Single owner
Lifetime Have their own lifetime Have their own lifetime Owner’s lifetime
Child Object Child objects all are independent Child objects belong to a single parent Child objects belong to single parent

所以,总结来说,聚合(Aggregation)是一种特殊的关联(Association),合成(Composition)是一种特殊的聚合(Aggregation)。
Association->Aggregation->Composition

image.png

实操

强制约定,从源指向目标
划线的时候,就定义谁是源,谁是目标