【菜鸟博士编程绘图学习】14种UML介绍

Introduction to 14 kinds of UML
菜鸟博士Caesar


菜鸟博士Caesar Rookie Doc, Caesar


分享快乐 Share the joy

什么是UML?What is UML?


UML是Unified Model Language的缩写,中文是统一建模语言,是由一整套图表组成的标准化建模语言。

UML is short for Unified Model Language, and Chinese is Unified Modeling Language, a standardized modeling Language made up of a set of diagrams.

为什么要用UML?Why use UML?

通过使用UML使得在软件开发之前, 对整个软件设计有更好的可读性,可理解性,从而降低开发风险。同时,也能方便各个开发人员之间的交流。

The use of UML makes the whole software design more readable and understandable before the software development, thus reducing the development risk. At the same time, also can facilitate the communication between each developer.

UML提供了极富表达能力的建模语言,可以让软件开发过程中的不同人员分别得到自己感兴趣的信息。

UML provides a very expressive modeling language, which enables different people in the software development process to get the information they are interested in.


Page-Jones

在《Fundamental Object-Oriented Design in UML》 一书中总结了UML的主要目的,如下:

The main purposes of UML are summarized in the book Fundamental Object-Oriented Design in UML, as follows:

  1. 为用户提供现成的、有表现力的可视化建模语言,以便他们开发和交换有意义的模型。 Provide a ready-made, expressive visual modeling language for users to develop and exchange meaningful models

  2. 为核心概念提供可扩展性 (Extensibility) 和特殊化 (Specialization) 机制。 Provide Extensibility and Specialization mechanisms for the core concepts

  3. 独立于特定的编程语言和开发过程。 Independent of a specific programming language and development process

  4. 为了解建模语言提供一个正式的基础。 Provides a formal basis for understanding modeling languages

  5. 鼓励面向对象工具市场的发展。 Encourage the development of the market for object-oriented tools

  6. 支持更高层次的开发概念,如协作,框架,模式和组件。 Supports higher-level development concepts such as collaboration, frameworks, patterns, and components

  7. 整合最佳的工作方法 (Best Practices)。 Integrate Best Practices

UML图有哪些?What are the UML diagrams?
  • UML图分为结构图和行为图。 UML diagrams are divided into structure diagrams and behavior diagrams

  • 结构图分为类图、轮廓图、组件图、组合结构图、对象图、部署图、包图。 Structure diagrams are divided into class diagrams, outline diagrams, component diagrams, composite structure diagram diagrams, object diagrams, deployment diagrams, and package diagrams

  • 行为图又分活动图、用例图、状态机图和交互图。 The behavior diagram is divided into activity diagram, use case diagram, state machine diagram and interaction diagram

  • 交互图又分为序列图、时序图、通讯图、交互概览图。 The interaction graph is divided into sequence graph, time sequence graph, communication graph and interaction overview graph

UML图概览

Overview of UML diagrams

什么是类图?

What is a class diagram?

  • 【概念】 类图是一切面向对象方法的核心建模工具。类图描述了系统中对象的类型以及它们之间存在的各种静态关系。 [ concept ] class diagram is the core modeling tool of all object-oriented methods. Class diagrams describe the types of objects in a system and the various static relationships that exist between them

  • 【目的】用来表示类、接口以及它们之间的静态结构和关系。 [ purpose ] is used to represent classes, interfaces, and the static structures and relationships between them

❝在类图中,常见的有以下几种关系。 ❞

In class diagrams, the following relationships are common

泛化(Generalization)Generalization
  • 【泛化关系】是一种继承关系,表示子类继承父类的所有特征和行为。 A generalization is an inheritance relationship in which a subclass inherits all the characteristics and behavior of its parent class

  • 【箭头指向】带三角箭头的实线,箭头指向父类。 Arrow pointing to the solid line with the triangle arrow pointing to the parent class

实现(Realization)

Realization

  • 【实现关系】是一种类与接口的关系,表示类是接口所有特征和行为的实现。 An implementation relationship is a relationship between a class and an interface, indicating that a class is an implementation of all the characteristics and behaviors of an interface

  • 【箭头指向】带三角箭头的虚线,箭头指向接口。 Arrow pointing ] dotted line with a triangular arrow pointing to the interface

关联(Association)

Association

  • 【关联关系】是一种拥有关系,它使得一个类知道另一个类的属性和方法。 An association is a relationship of ownership that enables a class to know the properties and methods of another class

  • 【代码体现】成员变量 Member variable

  • 【箭头指向】带普通箭头的实线,指向被拥有者。双向的关联可以有两个箭头,或者没有箭头。单向的关联有一个箭头。 Arrow pointing a solid line with an ordinary arrow pointing to the owner. A two-way association can have two arrows, or it can have no arrows. The one-way association has an arrow


❝自己买的车,想什么时候开就开。但是车是车,人是人,没有整体与部分的关系。 ❞

You Buy your own car, you drive it whenever you want. But a car is a car and a person is a person. There is no relationship between the whole and the parts. Oh, shit

聚合(Aggregation)Aggregation
  • 【聚合关系】是一种整体与部分的关系。且部分可以离开整体而单独存在。聚合关系是关联关系的一种,是强的关联关系;关联和聚合在语法上无法区分,必须考察具体的逻辑关系。 An aggregate relationship is a relationship between a whole and a part. And parts can exist independently of the whole. The relation of cohesion is a kind of relation of relevance, which is strong. The relation of cohesion and relevance can not be distinguished in grammar, so the concrete logical relation must be considered

  • 【代码体现】成员变量 Member variable

  • 【箭头指向】带空心菱形的实线,空心菱形指向整体。 The arrow points to the solid line with the hollow diamond, the hollow diamond points to the whole


❝电脑有键盘才能输入信息,电脑是整体,键盘是部分,键盘也可以离开电脑,单纯的拿去敲。所以是聚合。 ❞

Computer keyboard can input information, the computer is the whole, the keyboard is part of the keyboard can also leave the computer, simply take to knock. So it's an aggregation. Oh, shit

组合(Composition)Composition
  • 【组合关系】是一种整体与部分的关系。但部分不能离开整体而单独存在,组合关系是关联关系的一种,是比聚合关系还要强的关系。 A compositional relationship is a relationship between a whole and a part. But a part can not exist without the whole, and a composition relation is a kind of association relation, which is stronger than an aggregation relation

  • 【代码体现】成员变量 Member variable

  • 【箭头指向】带实心菱形的实线,实心菱形指向整体。 The arrow points to the solid line with the solid diamond, the solid diamond points to the whole


❝鸟是整体,翅膀是部分。鸟死了,翅膀也就不能飞了。所以是组合。我们再看一下,下面的一组经典的聚合组合关系的例子。 ❞

The bird is the whole, the wing is the part. When a bird dies, its wings can't fly. So it's a combination. Let's look again at the following examples of a classic set of aggregate-combinatorial relationships. Oh, shit


❝一个公司拥有多个部门,公司和部门之间是组合关系,公司破产了,部门就不复存在了。部门和员工是聚合关系,部门被裁掉,员工就换下家了。 ❞

A company has more than one department, the relationship between the company and the department is a combination, the company goes bankrupt, the department no longer exists. Departments and employees are aggregated, and when departments are cut, employees move on. Oh, shit

依赖(Dependency)Dependency
  • 【依赖关系】是一种使用关系,即一个类的实现需要另一个类的协助。 Dependency is a usage relationship in which the implementation of one class requires the assistance of another class

  • 【箭头指向】带普通箭头的虚线,普通箭头指向被使用者。 Arrow pointing a dashed line with an ordinary arrow pointing to the person being used


❝老司机只管开车,车是谁的不重要,给什么车开什么车。 ❞

Old driver just drive, the car is not important, to what car to drive what car. Oh, shit

什么是组件图?What is a component diagram?
  • 【概念】描绘了系统中组件提供的、需要的接口、端口等,以及它们之间的关系。 [ concept ] describes the interfaces, ports, etc. that are provided, required, and the relationships between components in a system

  • 【目的】用来展示各个组件之间的依赖关系。 [ purpose ] to show the dependencies between the components


❝订单系统组件依赖于客户资源库和库存系统组件。中间的虚线箭头表示依赖关系。另外两个符号,表示组件连接器,一个提供接口,一个需要接口。 ❞

The order system component is dependent on the customer repository and the inventory system component. The dotted arrow in the middle indicates a dependency. Two additional symbols representing component connectors, one providing an interface and one requiring an interface. Oh, shit

什么是部署图?What is a deployment plan?
  • 【概念】描述了系统内部的软件如何分布在不同的节点上。 [ concept ] describes how the software within a system is distributed across different nodes

  • 【目的】用来表示软件和硬件的映射关系。 [ purpose ] is used to represent the mapping between software and hardware


❝图中简单的表示,不同机器上面部署的不同软件。 ❞

A simple representation of the different software deployed on different machines. Oh, shit

什么是对象图?What is an object graph?
  • 【概念】对象图是类图的一个实例,是系统在某个时间点的详细状态的快照。 [ concept ] an object graph is an instance of a class graph, a snapshot of the detailed state of a system at a point in time

  • 【目的】用来表示两个或者多个对象之间在某一时刻之间的关系。 Used to indicate the relationship between two or more objects at a given moment


❝图中就是描述的,某时间点

That's what's depicted in the graph, a point in time

bat

蝙蝠

这个公司有一个研发部,一个销售部,两个部门只有一个人

The company has a research and development department, a sales department, two departments only one person

  • iisheng 爱生

。 ❞

  • !important,Helvetica Neue,Helvetica,PingFang SC,Microsoft YaHei,Source Han Sans SC,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif;font-weight:bold;font-style:normal;text-decoration:;color:#000000;background:;letter-spacing:0pt;vertical-align:baseline">什么是包图? ! important,Helvetica Neue,Helvetica,PingFang SC,Microsoft YaHei,Source Han Sans SC,Noto Sans CJK SC,WenQuanYi Micro hei,Sans-serif; font-weight: bold; font-style: normal; text-decoration: ; color: # 000000; background: ; letter-spacing: 0 pt; vertical-align: baseline”> something something something something something something something something something something something something something?

  • 【概念】描绘了系统在包层面上的结构设计。 [ concept ] describes the structural design of the system at the package level

  • 【目的】用来表示包和包之间的依赖关系。 [ purpose ] is used to express dependencies between packages and packages


《Use》关系表示使用依赖,

"Use" relation means to Use dependence,

Web Shopping

网上购物

依赖

Depend on

Payment

付款

《Merge》关系表示合并,

the "Merge" relationship means a merger,

Web Shopping

网上购物

  • 合并了 Merged

Shopping Cart

购物车

就拥有了

And you have it

Shopping Cart

购物车

  • 的功能《Access》关系表示私有引入,比如代码中的指定包名类名 The function of "Access" relationship means private introduction, such as the code in the specified package name class name

《Import》关系表示公共引入,比如Java中的

the Import relationship represents a public introduction, such as in Java

import

进口

之后,就可以直接使用

After that, it's ready to go

import

进口

包中的类了。什么是组合结构图?Package of classes. What is the composite structure diagram?
  • 【概念】描述了一个"组合结构"的内部结构,以及他们之间的关系。这个"组合结构"可以是系统的一部分,或者一个整体。 [ concept ] describes the internal structure of a "composite structure" and the relationship between them. This "composite structure" can be part of a system, or a whole

  • 【目的】用来表示系统中逻辑上的"组合结构"。 [ objective ] is used to represent the logical "composition structure" of a system


❝图中描述了

In the diagram, you can see

Car

汽车

是由车轴连接着的两个前面轮子、两个后面轮子,和引擎组合的。 ❞

Is a combination of two front wheels, two rear wheels, and an engine connected by an axle. Oh, shit

什么是轮廓图?What is a contour map?
  • 【概念】轮廓图提供了一种通用的扩展机制,用于为特定域和平台定制UML模型。 [ concept ] contour diagrams provide a common extension mechanism for customizing UML models for specific domains and platforms

  • 【目的】用于在特定领域中构建UML模型。 【 objective 】 to construct a UML model in a specific domain


❝图中我们定义了一个简易的

In the graph, we define a simple

EJB

的概要图。

A summary of the.

Bean

豆子

是从

From..

Component

组件

扩展来的。

It's an extension.

Entity Bean

实体 Bean

And

Session Bean

会话 Bean

继承了

Inherited it

Bean

豆子

.

EJB

拥有

Own

Remote

遥远

And

Home

接口,和

Interface, and

JAR

包。 ❞

Bag. bag

什么是用例图?What is a use case diagram?
  • 【概念】用例图是指由参与者、用例,边界以及它们之间的关系构成的用于描述系统功能的视图。 [ concept ] a use case diagram is a view that describes the functions of a system, consisting of actors, use cases, boundaries, and relationships between them

  • 【目的】用来描述整个系统的功能。 [ purpose ] used to describe the function of an entire system


用例图中包含以下三种关系:

The use case diagram contains the following three relationships:

  • 包含关系使用符号《include》,想要查看订单列表,前提是需要先登录。 Include relationships use the symbol "include" to see the list of orders, provided that you are logged in first

  • 扩展关系使用符号《extend》,基于查询订单列表的功能,可以增加一个导出数据的功能 The extended relationship uses the symbol extend, which adds the ability to export data based on the ability to query an order list

  • 泛化关系,子用例继承父用例所有结构、行为和关系。 Generalized Relationships, where the child use case inherits all the structures, behaviors, and relationships of the parent use case

什么是活动图?What is an activity chart?
  • 【概念】描述了具体业务用例的实现流程。 [ concept ] describes the implementation flow of a specific business use case

  • 【目的】用来表示用例实现的工作流程。 [ purpose ] represents the workflow of a use case implementation


❝图中简单描述了,从开始到登录到查看订单列表,或者登录失败直接结束。 ❞

The simple description in figure is from start to login to view the list of orders, or the end of a login failure. Oh, shit

什么是状态机图?What is a state machine diagram?
  • 【概念】状态机图对一个单独对象的行为建模,指明对象在它的整个生命周期里,响应不同事件时,执行相关事件的顺序。 [ concept ] a state machine diagram models the behavior of a single object, specifying the order in which the objects perform related events as they respond to different events throughout their life cycle

  • 【目的】用来表示指定对象,在整个生命周期,响应不同事件的不同状态。 [ purpose ] is used to indicate the state of a specified object in response to different events throughout its life cycle


❝图中描述了,门在其生命周期内所经历的状态。 ❞

The diagram depicts the states that a door experiences during its life cycle. Oh, shit

什么是序列图?What is a sequence diagram?
  • 【概念】序列图根据时间序列展示对象如何进行协作。它展示了在用例的特定场景中,对象如何与其他对象交互。 [ concept ] sequence diagrams show how objects collaborate based on time series. It shows how an object interacts with other objects in a particular scenario of a use case

  • 【目的】通过描述对象之间发送消息的时间顺序显示多个对象之间的动态协作。 【 objective 】 to display the dynamic cooperation among multiple objects by describing the time sequence of sending messages between them


❝图中展示的是支付宝条码支付场景的序列图。其中,

This is a sequence diagram of the Alipay bar code payment scenario. Among them,

loop

循环

是循环,

It's a loop,

alt

谷丙转氨酶

是选择,序列图的其他关系这里就不介绍了。 ❞

is selection, and other relationships in the sequence diagram are not covered here. Oh, shit

什么是通讯图?What is a communication map?
  • 【概念】描述了收发消息的对象的组织关系,强调对象之间的合作关系而不是时间顺序。 [ concept ] describes the organization of objects that send and receive messages, emphasizing cooperative relationships rather than chronological order

  • 【目的】用来显示不同对象的关系。 [ purpose ] used to show the relationships between different objects


❝图中展示了一个线上书店的通讯图,方框和小人表示生命线,不同生命线之间可以传递消息,消息前面的数字可以表达序列顺序。 ❞

The diagram shows a communication diagram of an online bookstore. The squares and little people represent lifelines. Messages can be passed between different lifelines. The numbers in front of the messages can express the sequence. Oh, shit

什么是交互概览图?What is an interactive overview?
  • 【概念】交互概览图与活动图类似,但是它的节点是交互图。 An interaction overview diagram is similar to an activity diagram, but its nodes are interaction diagrams

  • 【目的】提供了控制流的概述。 [ objective ] provides an overview of the control flow


❝图中表示一个调度系统的交互概览图,跟活动图很像。其中

The diagram represents an interactive overview of a scheduling system, much like the activity diagram. Among them

sd

动物学家

的框代表具体的交互流程,

Box represents a specific interaction flow,

ref

裁判

框代表使用交互。 ❞

the box represents the use of interaction

什么是时序图?What is a sequence diagram?
  • 【概念】时序图被用来显示随时间变化,一个或多个元素的值或状态的更改。也显示时控事件之间的交互和管理它们的时间和期限约束。 [ concept ] a sequence diagram is used to show changes in the value or state of one or more elements over time. It also shows the interaction between time-controlled events and the time and deadline constraints that govern them

  • 【目的】用来表示元素状态或者值随时间的变化而变化的视图。 -LSB- purpose ] a view that represents the change in the state or value of an element over time


❝图中展示了老年痴呆病人随着时间的变化病情的变化。 ❞

The picture shows the change of the patient's condition with the time. Oh, shit

参考文献: [1]:《Learning UML 2.0》 [2]: https://www.uml-diagrams.org/ [3]: https://www.visual-paradigm.com/guide/ [4]: https://sparxsystems.com/resources/tutorials/

2.0: 《学习 UML 2.0》 , https://www.UML-diagrams.org/ , https://www.visual-paradigm.com/guide/ , https://sparxsystems.com/resources/tutorials/