UML-the relationship between classes

Associate

Association relationship representation

Ordinary Association

                                   There is a structural relationship between two classes represented by a straight line 

                           works in is the association name role name is the role name

 1. Name (Association name): used to describe the nature of the relationship.

2. Role: When a class is at one end of the association, the class plays a specific role in the relationship; the role is to manage the responsibility of the class near it to the class at the other end.

3. Multiplicity (Multiplicity): The multiplicity of the associated role is to indicate how many interconnected objects are in an associated instance.

Exactly One 1
Zero or More 0...*
Zero or More *
One or More

1...*

Zero or One 0...1
Specified Range 2..4
Multiple,Disjoint Ranges 2,4...6

               One-way association

               

                                           The student uses the single player to generate an attribute in the student’s class. The type of the attribute is the single player

               Two-way association

                                           Both classes will have attributes of each other 

               One class is associated with multiple classes

               Self-association

                                            The relationship established by a class with itself. Employee can be worker or chef, they are responsible relationship

Aggregation

It describes the loosely coupled relationship between the whole and the part, which is represented by a hollow diamond.

 Bookshelves and books. There are many books on a bookshelf. A book can be placed on a bookshelf. However, a bookshelf can hold 0 or more books. When the bookshelf is not available, the books can exist independently, and there is no clear statement constraint between the two .

Composition

It describes the tightly coupled relationship between the whole and the part, which is represented by a solid diamond.

Use solid descriptions to mainly describe their life span. Only when there are people can they have arms and heads. They are a kind of affiliation. The existence of the whole, the existence of the individual is a combination. 

 

 

rely

Dependency representation

 It is a usage relationship, indicating that a change in the specification of one thing may affect another thing that uses it, and the class depends on the class pointed by the arrow. Generally, class A needs to use class B, we have to say that class A depends on class B.

                 Course scheduling depends on the course. Generally speaking, the dependency relationship refers to the relationship of use. What I'm talking about here is that course scheduling needs to use course classes, how to use it, that is, there is course in the parameter of the course scheduling method add, so courses schedule needs to use course.

Generalization

Generalization relation representation

Describes the inheritance between classes.

There are two types of inheritance

             Single inheritance

                      A subclass has one and only one parent class, and cannot have two or more parent classes

             Double inheritance

                      A class has two or more parent classes

 

The parent category is Vehicle, which is subdivided into LandVehicle and WaterVehicle. For these two vehicles, they are single inheritance, and there is only one parent vehicle. But for Amphibious Vehicles (Amphibious Vehicle), he has two fathers, which belong to multiple inheritance, so there are two different sexes (vehicles have speed v, therefore road vehicles have a v, water vehicles have a v. Then the amphibious vehicle has two When the car inherits the parent class, it inherits two v, and there may be conflicts between the two v at runtime). A class in java can only inherit one parent class, and multiple inheritance is not allowed. If you want to, you can only add one interface. In the c language, a keyword is needed for multiple inheritance

 

achieve

Realization of relationship representation

 

It is the semantic relationship between class elements, in which one class element describes the contract that another class element guarantees to achieve.

Guess you like

Origin blog.csdn.net/weixin_44663188/article/details/108901779