Six Kinds of Relations Between Class and Class and UML Diagram

Class relationship: generalization (inheritance) = implementation> composition> aggregation> association> dependency

 

Generalization: (is-a), the inheritance relationship between class and class, interface and interface

****************************************************************************************

Implementation: refers to the function that a class implements the interface interface (there can be multiple)

****************************************************************************************

Association: The existence of Type A as the attribute style of Type B, that is, the "has" relationship

This kind of relationship is stronger than dependence. There is no contingency of dependence. The relationship is not temporary. It is generally long-term, and the relationship between the two parties is generally equal.

classification:

One-way association : Type A association Type B   Climate: Climate

Two-way association: Type A is associated with Type B, and Type B is associated with Type A

Multiplicity:

One-to-one association : a student can only study in one class

One-to-many association : a student can participate in multiple classes of learning

The solution to one-to-many associations is collections and arrays

Aggregation: It is a relatively strong relationship, the whole-part

Part can exist independently, so it is a relatively weak ownership relationship

Geese-big geese

Combination: It is a stronger relationship, and the part completely depends on the existence of the whole

The " whole" is responsible for the life cycle of the "parts", and they live and die together ; and the existence of the " parts" alone has no meaning, it is a relatively strong ownership relationship

Wild Goose-Wings

Summary of aggregation and composition:

1. Different constructors

Aggregate class: The constructor contains another class as a parameter . Goose is used as a parameter in the construction function of GooseGroup. Goose can exist independently from the geese.

Composite class: the instantiation of another class is included in the constructor . It shows that before instantiating the wild goose, Wings must be instantiated. These two classes are tightly coupled, coexisting and extinct. Wings cannot exist independently of Goose.

2. The encapsulation of information is different

   Aggregation: The client can understand the geese and the wild geese at the same time, because they are independent.

   Combination: The client only knows the wild geese, and does not know the existence of wings at all, because the wings are tightly encapsulated in the wild geese.

****************************************************************************************

Dependence: (use-a), which means that one class A uses another class B

Features: The used type B changes will affect the type A, this relationship is weak and accidental

Specific performance: Class B is used as a parameter in the method of Class A

For example: people and cars

Association and dependency:

Association is a "has" relationship, and dependency is a "use" relationship

Class A is associated with Class B, which means that Class B exists as an attribute of Class A

Class A depends on Class B, which means that Class B exists as a method parameter of Class A

Dependencies are only generated when they are called

The association relationship is generated when the class is instantiated , and the relationship ends when the class is destroyed

Guess you like

Origin blog.csdn.net/CharmaineXia/article/details/110641925