domain model, object model, system sequence diagram and interaction diagram in UML diagram

UML diagram (Unified Modeling Language, Unified Modeling Language) is a standardized modeling language for describing, visualizing, constructing and recording software systems. In UML, there are many types of diagrams, including domain model (Domain Model), object model (Object Model) and system sequence diagram (System Sequence Diagram). These diagrams are used to describe different levels and aspects of the system.

domain model (domain model)

Domain models focus on the actual problem domain and help us identify key concepts, requirements, and relationships between concepts. Generally, when dealing with a practical problem, we first use the domain model to analyze the key concepts and the relationship between each concept.

For example, we want to build a library system now. There are books and users in the library. We need to record which books the users have borrowed. Then we can extract two key concepts, Library Account and Book, and their relationship It can be expressed as:

The corresponding code representation is as follows:

class Account {
id : int ;
lateFees : int ;
borrowed: List <Book>;
boolean borrow( Book) { …}
void save();
}
class Book { … }

When drawing the domain model, we are limited to drawing the object name and the attributes it contains. Here, there is actually another attribute in our library account, which is borrowedBook, but we have already indicated the relationship between it and Book through a connecting line. The inclusion relationship, so there is no need to write the book into the attribute of the library account redundantly.

The two concepts here are connected by a line segment, and the relationship between them is indicated in words, and then one library account corresponds to * that is, multiple Books, indicating the quantitative relationship between the two. In fact, in most cases, the line segment in the middle has an arrow (here it should be a right arrow, indicating library account borrow Book, if it is a left arrow, the above comment should be borrowed by), the arrow is not mandatory, it belongs to dispensable.

In the domain model, for the "has a" relationship, there are two different drawing methods about Composition and Aggregation. The main difference between them is the life cycle relationship between the whole and the part and the independence of the part. Look directly at the picture:

Composition (combination) and Aggregation (aggregation) use solid and hollow notation to distinguish in UML class diagrams. Composition (combination) : The composition relationship is represented by a solid diamond arrow in the UML class diagram . The rhombus end points to the whole, the arrow end points to the part, and the life cycles of the whole and part are closely related. In a compositional relationship, a part is meaningless without a whole. For example, a person has hands and steps, if separated from the person, then the hand and leg alone are meaningless.

Aggregation (aggregation) : The aggregation relationship is represented by a hollow diamond arrow in the UML class diagram . The rhombus end points to the whole and the arrow end points to the part. The hollow diamond indicates that the whole and part in the aggregation relationship have relatively independent life cycles. In an aggregation relationship, even if a part is separated from the whole, it can still exist independently. For example, wheels and cars, wheels can exist alone.

object model

In fact, the object model is very similar to the domain model, that is, the implementation details are added on the basis of the domain model, such as the type of member variables in the class, the methods, parameters, and return value types contained in the class. For example, for the library account just now, it is expressed like this in the object model:

Among them, borrow(book), returnItem(book) and payFees(int) all belong to the method of this library account and are also its responsibilities. Through the domain model, we are more aware of the specific implementation details and method responsibilities of different objects. If the Domain Model is at a higher level of abstraction and is closely related to real-world problem domains, then the Object Model is at a lower level of abstraction and is closely related to software implementation.

Later, I plan to summarize a complete project, from domain model, object model to the final Java code to give examples, and I will write it if I have time.

System Sequence Diagram (system sequence diagram)

System Sequence Diagram (SSD) is a model used to describe the sequence of events on the system boundary, which shows the interaction process of the system in a specific usage scenario. System sequence diagrams only focus on system-level components such as users and the entire system. This helps us focus on the overall behavior of the system rather than focusing on internal details. For example, for the operation of library system users borrowing books, the system sequence diagram can be expressed as follows:

Through the system sequence diagram, we can clearly show the possible interaction methods and interaction sequences between the user and the system, and at the same time, some possible responses are indicated by the dotted back arrows. The system sequence diagram is an important tool in the process of object-oriented design, which can help us to understand and design the interaction of the system effectively.

Interaction Diagrams

Interaction Diagrams are a modeling tool used to represent the interaction and communication between objects, and are used to describe the behavior and collaboration within the system. There are two common representations of interaction diagrams: sequence diagrams (Sequence Diagrams) and communication diagrams (Communication Diagrams). Let’s talk about the sequence diagram here. The sequence diagram is very similar to the system sequence diagram above, but it can describe the interaction between more specific objects or classes, rather than just looking at the whole as a system. Come to a picture to understand:

For the entire library system, there are many objects in it, and how these objects interact and transmit information can be well depicted through the sequence diagram in the interaction diagram.

summary:

This article summarizes the definitions, usage scenarios and drawing methods of several common diagrams in UML diagrams, including domain model, object model, system sequence diagram and interaction diagram.

Guess you like

Origin blog.csdn.net/weixin_44492824/article/details/130498400