Introduction to UML


The Unified Modeling Language (UML) is a visual modeling language for designing software. It is characterized by simplicity, unity, graphics, and the ability to express dynamic and static information in software design.
Starting from different perspectives of the target system, UML defines nine types of diagrams, including use case diagrams, class diagrams, object diagrams, state diagrams, activity diagrams, sequence diagrams, collaboration diagrams, component diagrams, and deployment diagrams.

1. Class diagram concept

A class diagram (Class diagram) shows the static structure of the model, especially the classes that exist in the model, the internal structure of the classes, and their relationship with other classes. Class diagrams do not display transient information. Class diagrams are a major component of object-oriented modeling.

2. The role of class diagrams

  • In software engineering, a class diagram is a static structural diagram that describes the system 类的集合, 类的属性and 类之间的关系can simplify people's understanding of the system
  • The class diagram is 系统分析an 设计阶段important product of the sum 系统编码and 测试an important model of the sum

3. Class diagram notation

3.1, class representation method

  1. In a UML class diagram, a class is represented by a rectangle containing, ** and ** with a dividing line. For example, the following figure represents an Employee class, which contains three attributes of name, age and address, and a work( 类名)属性(field) method 方法(method) .

image.png

  1. The plus sign and minus sign before the attribute/method name indicate the visibility of this attribute/method. There are three symbols for visibility in UML class diagrams:
  • +: means public
  • -: Indicates private
  • #: means protected
  1. The full representation of the property is: VisibilityName:Type[=default]
  2. The full representation of a method is: visibility name (parameter list) [ : return type]

The content inside the square brackets is optional, and there are also those that put the type in front of the variable name and the return value in front of the method name

3.2, the representation method of the relationship between classes

3.2.1. Relationship

  • Association relationship is a kind of object 引用关系, which is used to represent the connection between one type of object and another type of object, such as teacher and student, master and apprentice, husband and wife, etc. Association relationship is the most commonly used relationship between classes, which can be divided into general association relationship, aggregation relationship and combination relationship.
  • We start with general associations. Association can be divided into one-way association, two-way association, self-association
  1. One-way association:

image.png
A unidirectional association is represented by a in a UMI class diagram 带箭头的实线. The figure above shows that each customer has an address, which is realized by letting the Customer class hold a member variable class of type Address.

  1. Bidirectional association:

image.png
From the above figure, we can easily see that the so-called two-way association means that both parties hold member variables of each other's type.
In a UMI class diagram, a bidirectional association is represented by a straight line without an arrow. In the above figure, a ListProduct> is maintained in the Customer class, indicating that a customer can purchase multiple products; a member variable of customer type is maintained in the Product class to indicate which customer purchased the product.

  1. self-association

image.png
A self-association is represented in a UMI class diagram by a line with an arrow pointing towards itself. The above picture means that the Node class contains member variables of type Node, that is, "self-contains itself

3.2.2. Aggregation relationship

  • The aggregation relationship is a kind of association relationship, yes 强关联关系, it is the relationship between the whole and the part. The aggregation relationship is also implemented through member objects, where member objects are part of the overall object, but member objects can 脱离整体对象而独立存在.
  • For example, the relationship between a school and a teacher, the school includes the teacher, but if the school is closed, the teacher still exists In the UML class diagram, the aggregation relationship can be represented by a 带空心菱形solid line, and the diamond points to the whole. The following figure shows the relationship between universities and teachers:

image.png

3.2.3 Combination relationship

  • Composition represents a whole-part relationship between classes, but it is a更强烈的聚合关系
  • In the composition relationship, the overall object can control the life cycle of the partial object, 一旦整体对象不存在,部分对象也将不存在and the partial object cannot exist without the overall object. For example, the relationship between the head and the mouth, without the head, the mouth would not exist.
  • In the UML class diagram, the composition relationship 带实心菱形is represented by a solid line, and the diamond points to the whole. The figure below shows the relationship between the head and the mouth:

image.png

3.2.4, dependencies

  • Dependency is a usage relationship, which is 耦合度最弱a way of association between objects, yes 临时性的关联. In code, a method of a certain class 通过局部变量、方法的参数或者对静态方法的调用来访问另一个类(被依赖类)中的某些方法performs some duties.
  • In UML class diagrams, dependencies are 带箭头的虚线represented using , with arrows from 使用类指向被依赖的类. The following figure shows the relationship between the driver and the car, and the driver drives the car:

image.png

3.2.5. Inheritance relationship

  • Inheritance relationship is 耦合度最大a relationship between objects, expressing a general and special relationship, a relationship between a parent class and a child class, and an inheritance relationship.
  • In a UML class diagram, a generalization relationship 带空心三角箭头的实线is used to represent an arrow pointing from a child class to a parent class. When implementing the code, use the object-oriented inheritance mechanism to realize the generalization relationship. For example, both the Student class and the Teacher class are subclasses of the Person class, and their class diagrams are shown in the following figure:

image.png

3.2.6, Realize relationship

  • The implementation relationship is the relationship between the interface and the implementing class. In this relationship, the class implements the interface, and the operations in the class implement all the abstract operations declared in the interface.
  • In UML class diagrams, the implementation relationship is 带空心三角箭头的虚线represented using , with an arrow pointing from the implementing class to the interface. For example, cars and boats implement vehicles, as shown in the image below

image.png

3.3 Summary of arrows

image.png

Guess you like

Origin blog.csdn.net/weixin_52487106/article/details/131210637