← Back to Hub ← 返回主页

Week 12: UML Modelling (Part 1) 第 12 周:UML 建模技术(一)

Learning Objectives 学习目标

  • Explain object-oriented DSS design methodologies.
  • Construct UML Use Case Diagrams for system functionalities.
  • Design UML Sequence Diagrams for user-system interaction timelines.

Step-by-Step Guide 分步指南

8.1 UML Use Case & Sequence Diagrams

  • Use Case Diagrams: Model system boundaries and the interactions between external actors (e.g., users, external servers) and specific use cases within the system.
  • Sequence Diagrams: Capture dynamic messages exchanged between objects over time. Focuses on chronological sequence of message flows:
    • Lifelines: Vertical dotted lines representing individual active objects during the scenario.
    • Activation Bars: Vertical rectangular boxes showing when an object is actively executing a task.
    • Messages: Horizontal arrows indicating message calls (solid arrow) and return results (dashed arrow).

Real-world Case: Uber Ride Booking

  • Uber engineers use Use Cases like "Request Ride" and "Process Payment" to specify system scope.
  • During design, a Sequence Diagram maps calls: Passenger -> RideManager (request) -> Driver (notification) -> RideManager (accept) -> PaymentGateway (authorize).

Reference: Uber Real-Time System Sequence Interactions

Comparison of UML Diagrams

UML Diagram Type View Focus Core Notations When to Use
Use Case Diagram System boundaries and external actors Stickman (actor), Oval (use case), Solid line (association) During requirements gathering to define project scope
Sequence Diagram Chronological communication between objects Lifelines, message paths, activations, actors During detail design to map function calls and controller flows
Class Diagram Static structural view of system classes Boxes with attributes and operations, multiplicities Before coding database models and class schemas

Sequence Diagram Messages

Chronological lifelines trace flows. For example: Manager -> UI: Click Analyze, then UI -> SolverController: runSimplex(), then SolverController -> DB: getConstraints().

8.1 UML 用例图与顺序图

  • 用例图 (Use Case Diagram): 对系统边界以及外部参与者(如用户、外部服务器)与系统内特定用例之间的交互进行建模。
  • 顺序图 (Sequence Diagram): 捕获对象之间随时间推移而交换的动态消息流。专注于消息传递的时间先后顺序:
    • 生命线 (Lifelines): 垂直虚线,表示在场景执行期间处于活动状态的单个对象。
    • 激活条 (Activation Bars): 垂直矩形条,显示对象正在积极执行任务的时间段。
    • 消息 (Messages): 水平箭头,指示消息调用(实线箭头)和返回结果(虚线箭头)。

真实企业案例:优步 (Uber) 乘车预订

  • Uber 工程师使用“请求乘车”和“处理付款”等用例图来指定系统边界。
  • 在设计过程中,顺序图映射了以下调用链:乘客 -> 派单管理器(请求) -> 司机(通知) -> 派单管理器(接受) -> 支付网关(授权)。

参考链接: Uber实时乘车顺序交互机制

UML 图表对比

UML 图表类型 分析视角侧重 核心图形标记 最佳应用时机
用例图 (Use Case) 系统边界和外部参与者的功能性交互 火柴人(参与者)、椭圆(用例)、实线(关联关系) 在需求收集阶段,用于定义项目功能和业务边界
顺序图 (Sequence) 对象之间信息传递的时间顺序流 生命线、同步/异步消息、激活框、参与者 在详细设计阶段,用于分析函数调用和控制层流转
类图 (Class) 系统静态结构以及类之间的关联 包含属性与方法的类框、多重性(如 1..*) 在开始编写数据库实体类和业务层代码之前

顺序图的时间轴流

顺序图展示了时间顺序。例如:经理 -> 界面: 点击分析,接着 界面 -> 求解控制器: runSimplex(),然后 求解控制器 -> 数据库: getConstraints()。

Concept Visualization 概念可视化

PassengerRideManagerDriver1. requestRide()2. notifyDriver()

Educational Infographic 教学信息图

Visual concept map explaining the key module topic: 解释该模块核心主题的视觉概念图:

Class: User - username: String - emailAddress: String + verifyPassword()

📊 Practical Decision Support Suite (Week 12) 📊 实用决策支持套件(第 12 周)

📐 UML Use Case & Sequence Diagram Syntax

Model user-system interactions in Draw.io / Visual Paradigm:

Actor: Manager Use Case: [Run Linear Programming Solver] -> include -> [Authenticate User] Sequence: Manager -> UI: Click "Solve" -> UI -> MBMS: Run Simplex LP -> MBMS -> UI: Return Optimal Solution

Tips 提示

UML stands for Unified Modeling Language. Remember that Sequence diagrams are DYNAMIC (show message flows over time) while Class diagrams are STATIC (show structures).
UML 代表统一建模语言。记住,顺序图是动态的(显示随时间推移的消息流),而类图是静态的(显示结构)。

Knowledge Check 知识自测

1. UML Sequence Diagrams are used to model what aspect of a system? UML 顺序图用于对系统的哪个方面进行建模?

Show Explanation 显示解析
Correct Answer: Option 2 正确选项:选项 2

2. The vertical dotted line in a UML sequence diagram represents: UML 顺序图中的垂直虚线代表:

Show Explanation 显示解析
Correct Answer: Option 2 正确选项:选项 2

3. UML is an abbreviation for: UML 是什么的缩写?

Show Explanation 显示解析
Correct Answer: Option 1 正确选项:选项 1

Practical Exercise 实践练习

Task 1: UML Use Case actor text format representation (e.g. colon actor name). 任务 1: UML 用例参与者文本格式表示(例如冒号参与者名称)。

Task 2: Mermaid syntax representing chronological message from Alice to Bob containing 'Hello'. 任务 2: Mermaid 语法表示 Alice 到 Bob 的包含 'Hello' 的按时间顺序的消息。

Task 3: SQL query to select all records from 'Diagrams' where Type is 'Sequence'. 任务 3: SQL 查询:从 'Diagrams' 表中选择 Type 为 'Sequence' 的所有记录。

Revision Guide 复习指南

Revision Checklist:

  • I can define actors and draw system boundaries in Use Case diagrams.
  • I understand sequence diagrams, lifelines, and activation indicators.
  • I can trace a complete data-query flow from a sequence diagram.

Key Concepts to Remember:

  • UML Use Case & Sequence Diagrams:
    • Use Case Diagrams: Model system boundaries and the interactions b...

Matching Game 配对游戏

Match the term on the left with its definition on the right. 将左侧的术语与右侧的定义进行配对。

Sequence Diagram
Vertical block showing active object execution显示活动对象执行状态的垂直方块
Activation Bar
UML diagram mapping dynamic message flows chronologically按时间顺序映射动态消息流的 UML 图
Lifeline
UML diagram defining system boundary and actor roles定义系统边界和参与者角色的 UML 图
Use Case Diagram
Vertical dotted line representing object existence代表对象生存周期的垂直虚线