抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

**Unified Modeling Language (UML)**又称统一建模语言或标准建模语言。

使用UML的面向对象图的方式来更明确、清晰的表达项目中的架构思想、项目结构、执行顺序等一些逻辑思维

UML模型的三部分构成:

  • 事物(Things):UML中最基本的构成要素,是具有代表性的成分的抽象;
  • 关系(Relationships):关系把事物联系在一起;
  • 图(Diagrams):图是事物和关系的可视化表示。

UML构建模块

事物

事物是是实体抽象化的最终结果,是 UML 构建块最重要的组成部分,事物的分类如下:

  • 结构事物
    • 接口
    • 协作
    • 用例
    • 组件
  • 行为事物
    • 交互
    • 状态机
  • 分组事物
  • 注释事物
    • 注释

关系

关系是另一个最重要的构建块UML,它显示元素是如何彼此相关联,此关联描述的一个应用程序的功能,UML中定义了四种关系:

  • 依赖关系
  • 协作
  • 泛化
  • 实现

UML图

UML 图的视觉效果是整个过程中最重要的部分。分为:

  1. 类图:类图描述系统所包含的类、类的内部结构及类之间的关系;
  2. 对象图:对象图是类图的一个具体实例;
  3. 用例图:用例图从用户的角度出发描述系统的功能、需求,展示系统外部的各类角色与系统内部的各种用例之间的关系;
  4. 顺序图:顺序图表示对象之间动态合作的关系;
  5. 协作图:协作图描述对象之间的协作关系;
  6. 活动图:活动图描述系统中各种活动的执行顺序。
  7. 状态图:状态图描述一类对象的所有可能的状态以及事件发生时状态的转移条件;
  8. 部署关系图:部署关系图定义系统中软硬件的物理体系结构;
  9. 组件图:组件图描述代码部件的物理结构以及各部件之间的依赖关系;

根据建模类型划分,可分为:

  • 结构建模
    • 类图
    • 对象图
    • 部署图
    • 包图
    • 复合结构图
    • 组件图
  • 行为建模
    • 活动图
    • 交互图
    • 用例图
  • 架构建模
    • 包图

UML类图

类图(Class Diagram)是面向对象系统建模中最常用和最重要的图,是定义其它图的基础。

类图主要是用来显示系统中的类、接口以及它们之间的静态结构和关系的一种静态模型。

类图不仅用于可视化描述和记录系统的不同方面,也为构建可执行代码的软件应用程序。

类图描述一类的属性和操作,也对系统的约束。被广泛应用于类图的建模的面向对象的系统中,因为它们是唯一的,可以直接映射到面向对象的语言的 UML 图。

类图显示集合的类,接口,关联,协作和约束,它也被称为作为结构图。

UMLClass

一个类图的综合例子

ClassDiagram

In the example above:

We can interpret the meaning of the above class diagram by reading through the points as following.

  1. Shape is an abstract class. It is shown in Italics.
  2. Shape is a superclass. Circle, Rectangle and Polygon are derived from Shape. In other words, a Circle is-a Shape. This is a generalization / inheritance relationship.
  3. There is an association between DialogBox and DataController.
  4. Shape is part-of Window. This is an aggregation relationship. Shape can exist without Window.
  5. Point is part-of Circle. This is a composition relationship. Point cannot exist without a Circle.
  6. Window is dependent on Event. However, Event is not dependent on Window.
  7. The attributes of Circle are radius and center. This is an entity class.
  8. The method names of Circle are area(), circum(), setCenter() and setRadius().
  9. The parameter radius in Circle is an in parameter of type float.
  10. The method area() of class Circle returns a value of type double.
  11. The attributes and method names of Rectangle are hidden. Some other classes in the diagram also have their attributes and method names hidden.

参考文献

W3CSchool——UML 教程

What is class diagram-visual Paradigm

评论

Gitalk评论系统对接至Github Issue,随心评论🐾🐾.....