The most comprehensive UML tutorial

Everything you want is here

The most comprehensive UML tutorial

written at the front

Statement, part of the information in this blog post is excerpted from 维基百科and Calvinsily的UML教程, the blog post does not involve advanced technology, it aims to share related technologies, save the time and cost of learning for most friends, and hope to make progress together with you!

Overview of UML

UML.png

What is UML?
  • UML is a standard language for specifying, visualizing, and documenting products for object-oriented development systems;

  • As a model language, UML allows developers to focus on building the model and structure of the product, rather than what programming language and algorithm implementation to choose;

  • UML is different from other common programming languages, such as C++, Java, COBOL, etc. It is a drawing language used to make software blueprints;

  • UML is not a programming language, but tools are available for generating code in various languages ​​using UML diagrams;

UML core

At the heart of UML are diagrams, which can be roughly categorized as structural diagrams and behavioral diagrams.
* The structure diagram is composed of static diagrams, such as class diagrams, object diagrams and other static diagrams;

  • Behavior diagrams are composed of dynamic diagrams like sequence diagrams, collaboration diagrams, etc.;

一个系统的静态和动态特性是通过使用这些图的可视化。

UML class diagram:

Class diagrams are the most popular UML diagrams used in the object-oriented society. It describes the objects and their relationships in a system and allows us to have a comprehensive understanding of the system before writing code correctly.
A single class diagram describes a specific aspect of the system, and a collection of class diagrams represents the entire system. Basically, a class diagram represents a static view of the system.

类图是唯一可以直接映射到面向对象的语言UML图。因此,它被广泛应用于开发者社区。

UML object diagram:

对象图是类图的一个实例. Therefore, the basic elements of a class of graphs are similar. Object graphs are made up of objects and links. At a particular moment, it captures an instance of the system.
Object graphs are used for prototyping, reverse engineering, and modeling real-world scenarios.

UML use case diagram:

Use case diagrams describe system functions from the user's point of view, and point out the operators of each function to capture the dynamic nature of the system.
A high-level design use case diagram is used to capture the requirements of the system, so it represents the functionality and flow of the system. While forward and reverse engineering of use case diagrams is not a good option, they still simulate it in a slightly different way.

UML interaction diagram:

Interaction diagrams that capture the dynamic nature of the system.
Interaction diagrams include 序列图and collaboration diagrams, in which: 序列图显示对象之间的动态合作关系,它强调对象之间消息发送的顺序,同时显示对象之间的交互; Collaboration diagrams describe the cooperative relationship between objects, and collaboration diagrams are similar to sequence diagrams, showing the dynamic cooperative relationship between objects.

UML state diagram:

A state diagram is a five diagram used to model the dynamic nature of a system. These graphs are used to simulate the entire life cycle of an object.
The state of an object is defined as the conditions under which the object exists, at a particular time and the object moves to other states, when certain events occur. Statecharts are also used for forward and reverse engineering.
The state diagram focuses on describing the process from one state to another state, mainly with the participation of external events.

UML activity diagram:

An activity diagram describes the activities to be performed to meet the requirements of the use case and the constraints between the activities, which is helpful for identifying parallel activities. Activity diagram is a special kind of state diagram, which is particularly important for the functional modeling of the system, emphasizing the control flow between objects.

The above are the related concepts of UML. In fact, let's talk about drawing. As for how to draw, let's learn together.

在这里我不会也不太可能将UML的各种元素都介绍一遍,我只介绍类图中各个类之间的关系;能看懂类图中各个类之间的线条、箭头代表什么意思后,也就足够应对 日常的工作和交流了;

Class diagrams are object-oriented modeling. They are generally used for conceptual modeling (conceptual modelling) of systematic classification applications, and can translate model modeling into code.

  • UML provides mechanisms to represent members of a class, such as properties and methods, and other information about them.
  • Designating the visibility of a class member (that is, any property or method) has the following symbols, which must precede the name of each member:
    member visibility.png

A class has three areas
* The top part is the class name
* The middle part contains the properties of the class
* The bottom part contains the methods of the class

image

Start with an example

Please see the following class diagram, mainly to see the relationship between classes:
uml_class_struct.png

  • The class diagram structure of the car is <>, indicating that the car is an abstract class;
  • It has two inherited classes: car and bicycle; the relationship between them is the realization relationship, which is represented by a dashed line with a hollow arrow;
  • The relationship between the car and the SUV is also an inheritance relationship, and the relationship between them is a generalization relationship, which is represented by a solid line with a hollow arrow;
  • The relationship between the car and the engine is a combination, represented by a solid line with a solid arrow;
  • There is an aggregate relationship between students and classes, represented by solid lines with hollow arrows;
  • The relationship between the student and the ID card is represented by a solid line;
  • Students need to use bicycles to go to school, and there is a dependency relationship with bicycles, which is indicated by a dotted line with an arrow;
Instance-level relationships

  • Generalization (Generalization), the reverse direction of inheritance, refers to a class (called parent class, parent interface) has another (or some) class (called subclass, subinterface) common functions. A subclass can be considered a special case of its parent class and can add new functionality. Represented by solid lines with hollow triangular arrows.

  • Realization (Realization) refers to the function of a class implementing the interface interface (which can be multiple); in Java, such a relationship is clearly identified by the keyword implements. Represented by dashed lines with hollow triangular arrows.

  • Dependency (Dependency) can be simply understood as a class A uses another class B, "...uses a ...", the dependent object is only used as a tool, and does not hold a reference to it. This usage relationship is accidental, temporary, and very weak, but changes in class B will affect A; at the code level, class B is used as a parameter by class A in a method (method). Represented by a dashed line with a dovetailed arrow. Indicates that a class depends on the definition of another class; a dependency only describes a relationship between classes and classes that are used and used.
  • Association The
    association relationship allows one class to know the properties and methods of another class; an object will hold a reference to another object for a long time, and the two associated objects do not have any mandatory constraints on each other. As long as the two agree, they can always Disassociation or association, they do not have any agreement on the issue of lifetime. The associated object can also be associated with other objects, so the association can be shared. At the code level, the associated class appears in the associated class in the form of a class attribute, or it may be that the associated class references a global variable whose type is the associated class. There are currently five different types of associations defined. Bi-directional and uni-directional associations are the most common.

  • Aggregate (Aggregate) is a special type of relationship that represents the whole and the part, and it is a "weak" containment ("... owns a...") relationship. The component class can exist independently without relying on the aggregate class, and can have their own lives. Periods, parts can belong to multiple whole objects, or can be shared (sharable) for multiple whole objects. For example, a pond with ducks (in a pond). Another example is the relationship between professors and courses. Another example is the library contains (owns a) students and books. Students can exist even without a library, and the relationship between students and the library is gathering. Aggregation may not involve more than two classes. Graphics are represented by hollow diamond-shaped arrow tails and solid lines.

The relevant introduction about UML and the most important class diagrams are introduced here. I believe you have already started UML at this time. Maybe you want to know more about TA. It doesn't matter.我已经为你准备了一份非常全面的学习资料,请点击文章末尾链接领取.

The most comprehensive UML tutorial
PS: Thanks to Calvinsily for organizing and sharing the UML tutorial, you can like it!

Please give a little red heart! Because your encouragement is the biggest motivation for my writing!

More exciting articles, please pay attention
- Personal Blog : darryrzhong Develop Paper


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324685493&siteId=291194637