- Abstract: this is an article about the unified modeling language, that is, the basic diagram used in UML. In this article, I will discuss the structure diagram, which is a new graph type that has been proposed in UML 2. Since the purpose of this series of articles is to help people understand the mark elements and their meanings, this article mainly involves class diagrams. You will soon know the reason for doing so. Subsequent articles will cover other diagrams contained in the structure category.
51cto recommendationTopic: Unified UML modeling language
This is an article about the unified modeling language, that is, the basic diagram used in UML. In this article, I will discuss the structure diagram, which is a new graph type that has been proposed in UML 2. Since the purpose of this series of articles is to help people understand the mark elements and their meanings, this article mainly involves class diagrams. You will soon know the reason for doing so. Subsequent articles will cover other diagrams contained in the structure category.
I would also like to remind readers that this series of articles are about UML mark elements, so these articles do not mean to provide guidance for the best way of modeling, or how to determine which content should be modeled first. On the contrary, the purpose of this article and this series of articles is to help you have a basic understanding of the syntax and meaning of the Mark element. With this knowledge, you should be able to read the graph and create your own graph with the correct mark element.
This article assumes that you have a basic understanding of object-oriented design. If some of you need help with object-oriented concepts, you can access. Read "What is a class ?" And what is inheritance ?" This section will provide you with sufficient understanding and help you read this article. In addition, David Taylor's book object-oriented technologies: a manager's Guide provides an excellent and high-level description of object-oriented design without a deep understanding of computer programming.
Yin and yang in UML 2
In UML 2, there are two basic graph categories: structure diagram and behavior diagram. Each UML diagram belongs to the two diagrams. The purpose of the structure diagram is to display the static structure of the modeling system. They include classes, components, and (or) object graphs. On the other hand, the behavior chart shows the dynamic behavior of objects in the system, including object methods, collaboration, and activities. An instance of a behavior diagram is an activity diagram, with an example diagram and a sequence diagram.
General Structure Diagram
As I said, the structure chart shows the static structure of the modeling system. Focus on the system components without considering the time. In the system, the static structure is propagated by the display type and Their instances. In addition to displaying the system type and Their instances, the structure chart also displays at least some relationships between these elements. If possible, it even displays their internal structures.
Throughout the entire software lifecycle, structural charts are useful to various team members. In general, these graphs support design verification and communication between individuals and teams. For example, business analysts can use class or object graphs to model current assets and resources, such as ledger, product, or geographic layers. Architects can use components and deployment diagrams to test/confirm whether their designs are adequate. Developers can use class diagrams to design and write documents for the system code (or code to be written) class.
Special Class Diagram
UML 2 regards the structure diagram as a classification; there is no "structure diagram" here. However, a class chart provides a primary instance of the structure chart type and an initial set of a set of Mark elements for all other structural charts. Because class diagrams are so basic, the rest of this article will focus on the class graph mark set. At the end of this article, you will have an understanding of how to draw a UML 2 class diagram, and have a solid foundation for understanding the other structure diagrams that will be involved in the subsequent article.
Basic
As mentioned earlier, a class chart aims to display the type of a modeling system. In most UML models, these types include:
- Class
- Interface
- Data Type
- Components
UML has a special name for these types: "Classifier ". Generally, you can regard classifier as a class, but technically, classifier is a more common term. It is better to reference the other three types above.
Class Name
Class UML represents a rectangle, vertically divided into three areas, 1 shows. The class name is displayed in the top area. The middle area lists the attributes of the class. The bottom area lists the operations of the class. When you draw a class Element on a class chart, you must have a top area, the following two regions are optional (when the figure description is only used to show the high-level details of the relationship between classifiers, the following two regions are unnecessary ). Figure 1 shows how a flight is modeled as a UML class. As we can see, the name is flight. We can see three attributes of the flight class in the middle area: flightnumber, departuretime, and flightduration. In the bottom area, we can see that the flight class has two operations: delayflight and getarrivaltime.
Figure 1: Flight class diagram
Class Attribute list
The attribute section of the class (Central Region) lists the attributes of each class on the separator line. The attribute section is optional. When you use it, it contains each attribute displayed in the list of classes. The line is in the following format:
To continue with the flight class example, we can use the property type information to describe the class attributes, as shown in table 1.
Table 1: attribute names of the flight class with association types
Attribute name |
Attribute type |
Flightnumber |
Integer |
Departuretime |
Date |
Flightduration |
Minutes |
|
In the business class diagram, the attribute type is usually consistent with the Unit, which may be meaningful to the readers of the diagram (for example, minute, dollar, and so on ). However, the class diagram used to generate Code requires that the class attribute types must be limited to the types provided by the program language, or included in the types of models implemented in the system.
Display specific properties with default values in the class diagram, which is sometimes useful (for example, in a bank account application, a new bank account is initially zero ). The UML specification allows the following marks to be used as the default values in the attribute list section:
name : attribute type = default value |
For example:
The default value of the display attribute is optional. Figure 2 shows that a bank account class has a type named balance, and its default value is 0.
Figure 2: shows a bank account chart with a default balance attribute value of $0.