Summary of various UML diagrams - essence

UML (Unified Modeling Language) is a unified modeling language, a standard language for specifying, visualizing, and documenting products of object-oriented development systems. The following will introduce the basic concepts of nine UML diagrams + package diagrams and the usage scenarios of each diagram.

1. Basic Concepts  

  As shown in the figure below, UML diagram is divided into use case view, design view, process view, implementation view and topology view, and can be divided into static view and dynamic view. Static diagrams are divided into: use case diagrams, class diagrams, object diagrams, package diagrams, component diagrams, and deployment diagrams. Dynamic diagrams are divided into: state diagrams, activity diagrams, collaboration diagrams, and sequence diagrams.

  1. UseCase Diagrams: 

    The use case diagram mainly answers two questions: 1. Who uses the software. 2, the function of the software. Describes the functions of the system from the user's point of view, and points out the executors of each function, emphasizing the user of the user, and what functions the system accomplishes for the executors.

  2、类图(Class Diagrams):

    The user abstracts into a class according to the use case diagram, which describes the internal structure of the class and the relationship between the classes. It is a static structure diagram. In UML class diagrams, the following relationships are common: Generalization, Realization, Association, Aggregation, Composition, and Dependency.

     The order of strength and weakness of various relationships: generalization = realization > composition > aggregation > association > dependency

  2.1. Generalization

    [Generalization relationship]: It is an inheritance relationship, indicating a general and special relationship, which specifies how the subclass inherits all the features and behaviors of the parent class. For example: Tiger is a kind of animal, that is, it has the characteristics of tiger and the commonality of animals.

    

  2.2. Implementation

    [Implementation relationship]: It is a relationship between a class and an interface, indicating that the class is the implementation of all the features and behaviors of the interface.

      

  2.3. Association

     [Association relationship]: It is an owned relationship, which enables one class to know the attributes and methods of another class; such as: teacher-student, husband-wife association can be bidirectional or unidirectional. Bidirectional associations can have two arrows or no arrows, and unidirectional associations have one arrow.

          [code embodiment]: member variable

      

  2.4. Aggregation 

    【聚合关系】:是整体与部分的关系,且部分可以离开整体而单独存在。如车和轮胎是整体和部分的关系,轮胎离开车仍然可以存在。

          聚合关系是关联关系的一种,是强的关联关系;关联和聚合在语法上无法区分,必须考察具体的逻辑关系。

          【代码体现】:成员变量

      

  2.5.组合

    【组合关系】:是整体与部分的关系,但部分不能离开整体而单独存在。如公司和部门是整体和部分的关系,没有公司就不存在部门。

         组合关系是关联关系的一种,是比聚合关系还要强的关系,它要求普通的聚合关系中代表整体的对象负责代表部分的对象的生命周期。

    【代码体现】:成员变量

    【箭头及指向】:带实心菱形的实线,菱形指向整体

          

  2.6.依赖  

     【依赖关系】:是一种使用的关系,即一个类的实现需要另一个类的协助,所以要尽量不使用双向的互相依赖.

        【代码表现】:局部变量、方法的参数或者对静态方法的调用

        【箭头及指向】:带箭头的虚线,指向被使用者

    

  2.7 各种类图关系

    

  3、对象图(Object Diagrams):

    描述的是参与交互的各个对象在交互过程中某一时刻的状态。对象图可以被看作是类图在某一时刻的实例。

      

  4、状态图(Statechart Diagrams):

    是一种由状态、变迁、事件和活动组成的状态机,用来描述类的对象所有可能的状态以及时间发生时状态的转移条件。

      

  5、活动图(Activity Diagrams):

    是状态图的一种特殊情况,这些状态大都处于活动状态。本质是一种流程图,它描述了活动到活动的控制流。    

交互图强调的是对象到对象的控制流,而活动图则强调的是从活动到活动的控制流。

活动图是一种表述过程基理、业务过程以及工作流的技术。

它可以用来对业务过程、工作流建模,也可以对用例实现甚至是程序实现来建模。

      

  5.1 带泳道的活动图

      泳道表明每个活动是由哪些人或哪些部门负责完成。

      

  5.2 带对象流的活动图

    用活动图描述某个对象时,可以把涉及到的对象放置在活动图中,并用一个依赖将其连接到进行创建、修改和撤销的动作状态或者活动状态上,对象的这种使用方法就构成了对象流。对象流用带有箭头的虚线表示。

    

  6、序列图-时序图(Sequence Diagrams):

    交互图的一种,描述了对象之间消息发送的先后顺序,强调时间顺序。

    序列图的主要用途是把用例表达的需求,转化为进一步、更加正式层次的精细表达。用例常常被细化为一个或者更多的序列图。同时序列图更有效地描述如何分配各个类的职责以及各类具有相应职责的原因。

    

  消息用从一个对象的生命线到另一个对象生命线的箭头表示。箭头以时间顺序在图中从上到下排列。 

  序列图中涉及的元素:

  6.1 生命线

    生命线名称可带下划线。当使用下划线时,意味着序列图中的生命线代表一个类的特定实例。

    

  6.2 同步消息

    同步等待消息

    

  6.3 异步消息

    异步发送消息,不需等待

        

  6.4 注释

    

  6.5 约束

    

  6.6 组合    

    组合片段用来解决交互执行的条件及方式。它允许在序列图中直接表示逻辑组件,用于通过指定条件或子进程的应用区域,为任何生命线的任何部分定义特殊条件和子进程。常用的组合片段有:抉择、选项、循环、并行。

  7、协作图(Collaboration Diagrams):

    交互图的一种,描述了收发消息的对象的组织关系,强调对象之间的合作关系。时序图按照时间顺序布图,而写作图按照空间结构布图

    

 

  8、构件图(Component Diagrams):

    构件图是用来表示系统中构件与构件之间,类或接口与构件之间的关系图。其中,构建图之间的关系表现为依赖关系,定义的类或接口与类之间的关系表现为依赖关系或实现关系。

    

  9、部署图(Deployment Diagrams):

    描述了系统运行时进行处理的结点以及在结点上活动的构件的配置。强调了物理设备以及之间的连接关系。

部署模型的目的:

描述一个具体应用的主要部署结构,通过对各种硬件,在硬件中的软件以及各种连接协议的显示,可以很好的描述系统是如何部署的;平衡系统运行时的计算资源分布;可以通过连接描述组织的硬件网络结构或者是嵌入式系统等具有多种硬件和软件相关的系统运行模型。

二、图的差异比较

  1.序列图(时序图)VS协作图

       序列图和协作图都是交互图。二者在语义上等价,可以相互转化。但是侧重点不同:序列图侧重时间顺序,协作图侧重对象间的关系。

共同点:时序图与协作图均显示了对象间的交互。

不同点:时序图强调交互的时间次序。

           协作图强调交互的空间结构。

    2.状态图VS活动图

      状态图和活动图都是行为图。状态图侧重从行为的结果来描述,活动图侧重从行为的动作来描述。状态图描述了一个具体对象的可能状态以及他们之间的转换。在实际的项目中,活动图并不是必须的,需要满足以下条件:1、出现并行过程&行为;2、描述算法;3、跨越多个用例的活动图。

    3.活动图VS交互图

  二者都涉及到对象和他们之间传递的关系。区别在于交互图观察的是传送消息的对象,而活动图观察的是对象之间传递的消息。看似语义相同,但是他们是从不同的角度来观察整个系统的。

三、UML与软件工程

  UML图是软件工程的组成部分,软件工程从宏观的角度保证了软件开发的各个过程的质量。而UML作为一种建模语言,更加有效的实现了软件工程的要求。

  如下图,在软件的各个开发阶段需要的UML图。

  

  下表是UML使用人员图示:

  

Guess you like

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