Software Modeling Overview & UML Model Diagram

software modeling

What is software modeling

Express ideas visually through the model, which is convenient for memory and further analysis, and facilitates team/colleague communication. Oral communication is easy to be distorted.

Software modeling embodies the idea of ​​software design, builds a bridge between requirements and implementation, and guides the specific implementation of software systems through models.

A model is not a complete representation of a software system, but an abstraction of the system under study.

抽象
指导
软件系统
软件模型

How to do software modeling

Software Modeling Principles

1. Choose the correct model, and the model must be connected with reality

2. From different perspectives, use different models to represent a system

3. The model is abstract, and it is to select one of the most prominent features of the system and perform a simplified representation. Therefore, it is necessary to use different models from different perspectives:

  • **External Perspective:** Modeling the system context or environment
  • **Interaction perspective: ** Model the interaction between the system and its environment or the components of the system, and establish a use case model
  • **Structural perspective:** Model the organization of the system or the structure of the data processed by the system, and establish a static model
  • **Behavioral perspective:** Model the dynamic behavior of the system and how the system responds to events, and establish a dynamic model

Software Modeling Method

There are different software modeling methods in different fields and scenarios, and their respective modeling ideas and modeling tools are also different, such as:

  • Structured Method
  • Object Oriented Method
  • Component Based Method
  • Service Oriented Method
  • Aspect Oriented Method
  • Model Driven Method
  • Formal Method

This chapter only introduces the most commonly used object-oriented modeling that is generally applicable to developers.

software modeling tools

With the continuous development and application of object-oriented technology, an object-oriented modeling standard, namely **UML (Unified Modeling Language)** unified modeling language has been formed. UML is a general graphical modeling language in object-oriented development, which has the following characteristics:

  • **Object-oriented: **Supports the main concepts of object-oriented, provides a batch of representation graphics and methods of basic model elements, and can express various object-oriented concepts concisely and clearly
  • **Visualization and strong presentation capabilities: **UML model diagrams can clearly represent the logical model and implementation model of the system, which can be used for modeling of various complex systems
  • **Process independent:** is a system modeling language, independent of the development process
  • **Independent of programming language:** The software system model established by UML can be realized by any object-oriented programming such as Java, C++, Smalltalk, etc.
  • **Easy to master and use:** UML graphic structure is clear, modeling is concise and clear, easy to master and use

UML content composition

UML consists of three parts:

  • **Things:** is an important part of UML and the most basic object-oriented building block in UML models. They are the most static part of the model, representing conceptual or physical elements.
  • **Relationship:** connects things closely together.
  • **Figure:** is a group of many things that are related to each other.
UML
事物
关系
静态
用例图
类图
对象图
部署图
动态
顺序图
合作图
状态图
活动图
结构事物
用例
接口
协作
活动类
组件
节点
行为事物
交互
状态机
组织事物
辅助事物
注释
关联
依赖
泛化
实现
1.1.5

9 UML Model Diagrams

picture use
Use
-Case Diagram
It is used to describe the role and the connection relationship between the role and the use case (such as: generalization, association and dependence); it is a static model to explain who will use the system and what they can do with the
system

Class DiagramClass Diagram
It is used to describe the classes in the system, as well as the relationship between each class (such as: generalization, implementation, dependency, association, aggregation, composition). is a static model .

Object DiagramObject Diagram
Very similar to a class diagram, it is an instance of a class diagram. An object diagram displays multiple object instances of a class, rather than the actual class. It describes not the relationship between classes, but the relationship between objects. It is a kind
of static model .
State
Diagram State Diagram
用于描述类的对象所有可能的状态,以及事件发生时状态的转移条件,是对类图行为上的补充,是一种动态模型
活动图
Activity Diagram
用于描述用例要求所进行的活动,以及活动间的约束关系,有利于识别并进行活动,是一种动态模型
顺序图
Sequence Diagram
也叫序列图或时序图,用于描述参与者与系统对象之间有序的交互过程,强调消息是如何在对象之间被发送和
接收的,是一种动态模型
合作图
Communication Diagram
也叫协作图,与顺序图相似。用于描述对象间动态合作关系。可以看成是类图和顺序图的交集,重点描述对象之间
的相互通信关系。如果强调时间和顺序,则使用时序图;如果强调上下级关系,则选择合作图。是一种动态模型
组件图
Component Diagram
也叫构件图,用于描述代码构件的结构以及各种构件之间的依赖关系,是一种静态模型
部署图
Deployment Diagram
用于描述系统的物理部署。例如计算机和设备,以及它们之间是如何连接件的。是一种静态模型

UML4+1视图

架构设计4+1视图的作用与关系

用例视图:使用用例图来描述

逻辑视图:描述系统的结构组成,使用类图、对象图

行为视图:用于系统运行时的交互过程,使用时序图、合作图、状态图、活动图

实现视图:也叫开发视图,使用组件图

部署视图:使用部署图

常见UML模型图

UML模型在软件开发流程中的应用

软件开发过程中,不同阶段需要用到不同的UML图,选择使用哪些图,需要深刻理解该图的主要用途,以及它表达的优势。

软件开发流程:

需求分析
概要设计
详细设计
编码阶段
测试

需求分析阶段:

​ 常用模型图:用例图

​ 对外部的参与者(Actor)以及它们所需要的系统功能建模,表示客户的需求

概要设计阶段:

​ 常用模型图:类图、对象图、合作图、状态图、时序图、活动图

​ 描述系统的静态结构,描述系统的动态特征

详细设计阶段:

​ 常用模型图:类图、对象图、合作图、状态图、时序图、活动图

​ 在详细设计阶段,把概要设计的结果扩展成技术解决方案,分析阶段的领域问题被嵌入在这个技术基础结构中

编码阶段:

​ 把设计阶段的类转换成某种面向对象程序设计语言的代码

测试阶段:

​ 常用模型图:类图、组件图、部署图

​ 不同的测试阶段使用不同的UML图,如:单元测试使用类图和类的规格说明;集成测试阶段典型的使用组件图、部署图

静态图

用例图

用例图关键元素

描述用例图首先要确定参与者,即角色(Actors),Actors表示提供或接收系统信息的人或系统,他们是与系统有交互作用的人或事物,代表一个系统的使用者或外部通信的目标。

用例是系统中的一个功能单元,被描述为角色与系统的一次交互。用例需要从角色希望系统提供的功能中提取,而不是以系统自身的角度来提取,满足参与者的需求的用例才是好用例。

用例间的常见关系有包含(Include)、扩展(Extend)、泛化(Generalization)。用例也可以叫Use,表示本用例会用到被包含的其他用例,被包含的用例是可以被重用的;扩展用例是可选的,在特定场景下可以补充基础用例,降低基础用例的复杂性。 泛化体现了父子关系,表明存在派生和继承。

类图

类图中的关系,箭头指向较小的部分

1、实现(Realization):

​ 是一种类与接口的关系,表示类是接口所有特征和行为的视线。例如:借阅者能查找书籍。

2、依赖(Dependency):

​ 是一种使用的关系(非持久,局部变量),有单向依赖和双向依赖。但尽量避免使用双向依赖。

3、泛化(Generalization):

​ 是一种继承关系,指定了子类继承父类的所有特征和行为。

4、关联(Association):

​ 是一种拥有的关系(持久的,全局变量),它使一个类知道另一个类的属性和方法。例如:借阅者的节约记录或预约记录。聚合和组合属于特殊的关联关系。

5、聚合(Aggregation):

​ 是整体与个体的关系,可以理解成把个体聚集在一起。个体可以独立分离,聚合为整体可以有更多功能。

6、组合(Composition):

​ 是整体与局部的关系,整体的对象负责代表局部的对象的生命周期,可以理解成整体是由局部组成的。没有局部就无法组成整体。(强依赖关系,局部是必要的)

动态图

动态图用于描述系统的对象交互、活动流程、状态变迁等行为动态模型,通常在完成静态图建模之后进行相应的动态图建模。

动态模型是描述系统的功能是如何完成的,用时序图、活动图、状态图从不同的角度来描述对象和对象之间的交互。

时序图

**时序图是强调消息时间顺序的交互图。**描述了不同对象之间协助完成预期行为的动态过程。顺序图具有直观、形象的优点。对呈现、理解不同对象间的交互关系时序具有较大的帮助。

时序图的主要绘图元素

  • 时序图将交互关系表示为一个二维图
  • 纵向是时间轴,时间沿竖线向下延伸
  • 横向代表了在协作中各独立对象的类元角色
  • 类元角色生命线表示
  • 消息用从一个对象的生命线到另一个对象生命线的箭头表示

设计考虑:

​ 为了突出关键设计步骤和设计意图,只关注主要交互流程,忽略无关异常分支

活动图

活动图用于对目标对象计算流程和工作流程建模

  • 一张活动图本质是一个流程图,它显示系统从一个活动到另一个活动的流程迁移
  • 在完成用例建模后,通过活动图表示用例的活动步骤,用于描述用例模型,有助于用例的动态行为建模
  • 也可以用于通用的流程图建模场景

四种基本建模元素

  • 活动Activity:表示一个执行步骤
  • 活动流Activity line:不同活动间的控制流或数据流
  • 控制符Control node:分支控制符decision/merge,并发控制符fork/join
  • 泳道Swimming line:用于表达不同的活动分组

活动图一般有开始和结束标志

泳道图是一种特殊的活动图,侧重“活动”属于哪个“对象”,同一对象的活动写在一条“泳道(Lane)”里面。

状态图

状态图描述了系统元素的状态条件和响应,它反映了类的对象可能具有的状态,以及状态变化的事件。

并不是所有的类都有相应的状态图,状态图仅用于具有下列特点的类:

具有若干个确定的状态,类的行为在这些状态会收到影响变为其他状态,另外也可为系统描述整体状态图。

状态图可用于类、用例或者整个系统。

主要概念:

  • 状态(State):状态描述了一个类对象生命周期中的一个时间段。体现一个类在当前时间所处的状态。
  • 事件(Event):事件是发生在时间和空间上的值得注意的事情,而这个事情可以引发状态变迁。事件可以分为:信号事件、调用事件、改变事件、时间事件等。
  • 转换(Transition):事件发生后类的状态变迁的过程。转换要有引起转换的触发器事件、监护条件、转换的动作和转换的目标状态。

设计考虑:

​ 为了维护状态的原子性,对于预约书借出过程,分解为两步:首先迁移到可借状态,然后再迁移到借出状态。

顺序图、活动图、状态图对比

顺序图、活动图、状态图都是描述事物的动态行为,其区别对比如下:

类别 建模对象 核心建模元素 建模时机 适用场景
顺序图 多个不同对象的交互过程 Role-Message 在类图完成之后进行 描述复杂的多对象间交互。并发、
分支过多的场景会影响可理解性,不宜太复杂
活动图 (特定对象或不同对象的)
不同活动之间的流动
Activity-Control Flow 在用例图或类图完成之后进行 描述涉及到复杂的活动步骤的用例。
特别是并发、分支等场景。
状态图 (特定对象的)不同状态变迁 State-Transition 在用例图或类图完成之后进行 涉及到复杂的状态变化的场景,也适用于
并发场景,如网络连接的会话状态等。

Tips:

  • 顺序图强调多个不同对象之间交互的先后顺序
  • 活动图强调复杂流程中活动单元的分支处理
  • 状态图强调特定对象在不同事件发生后的状态变化

小结

  • 软件建模是构建正确可信软件系统的基础,是对软件系统的抽象,指导软件系统的实现。
  • 软件建模是通过不同的视角,采用不同的模型去抽象描述一个系统(抽象,不是完整性描述),包括 外部视角、交互视角、结构化视角和行为视角
  • UML(Unified Modeling Language)是面向对象开发中一种通用的图形化建模语言,可视化、表达能力强,独立于过程和程序设计语言,易于掌握和使用。
  • UML包括4种事物、4种关系、9种图。各个元素不是孤立的,是相互有机结合来表示一个软件系统。
  • UML的9种模型又可以分为静态图动态图两大类,静态图描述了系统以及各对象的组织形式,动态图描述了系统以及对象之间的交互活动过程。
  • UML模型贯穿在软件开发流程各个环节。

Guess you like

Origin blog.csdn.net/q863672107/article/details/126696831