← Back to Hub ← 返回主页

Week 13: UML Modelling (Part 2) 第 13 周:UML 建模技术(二)

Learning Objectives 学习目标

  • Draw UML Class Diagrams for DSS database schemas.
  • Explain UML Class notations, attributes, operations, and multiplicities.
  • Analyze the benefits of OO technologies in DSS design.

Step-by-Step Guide 分步指南

8.2 UML Class Diagrams & Visibility Modifiers

  • Class Diagrams: Static structural diagrams displaying classes, attributes, methods, and relationships (inheritance, association).
  • Visibility Modifiers:
    • `+` Public: Visible to all other classes across the system.
    • `-` Private: Accessible only within the declaring class itself. Protects encapsulated data.
    • `#` Protected: Visible only within the declaring class and its subclasses.
  • Multiplicity Notations:
    • `1`: Exactly one instance (e.g., each account has exactly one profile).
    • `0..*`: Zero or more instances (e.g., a customer can place zero or more orders).
    • `1..*`: One or more instances.

Real-world Case: Airbnb Data Modeling

  • Airbnb class models use private fields for security:
  • `User` Class: Private attributes `-ssn` and `-passwordHash` with public method `+login()`.
  • Multiplicity: A `Host` [1] class has an association relationship of [0..*] with `Listing` class.

Reference: Airbnb Data Structure Modeling

UML Class Diagram Notations

Element UML Syntax Meaning / Explanation Example
Visibility Modifier - or + - means private variable; + means public function -salesData: double
Attributes name: type Variable name followed by data type +solverName: String
Operations name(params): return Function name with arguments and return data type +runOptimization(vars): double
Multiplicity 1, *, 1..* Determines how many objects can connect to each other 1 Model can reference 1..* Datasets

Benefits of Object Oriented DSS

  • Reusability: Extend existing base model classes (e.g. OptimizationModel) to create new models without rewrites.
  • Encapsulation: Keeps DBMS query code hidden behind private parameters, making changes safe.

8.2 UML 类图与可见性修饰符

  • 类图 (Class Diagram): 静态结构图,展示类、其属性、方法以及类之间的关系(如继承、关联)。
  • 可见性修饰符 (Visibility):
    • `+` 公有 (Public): 对整个系统中的所有其他类可见。
    • `-` 私有 (Private): 仅在声明它的类内部可访问。用于保护封装的数据。
    • `#` 保护 (Protected): 仅对声明它的类及其子类可见。
  • 多重性规则 (Multiplicity):
    • `1`: 仅一个实例(例如,每个帐户正好有一个用户画像)。
    • `0..*`: 零个或多个实例(例如,一个客户可以下零个或多个订单)。
    • `1..*`: 一个或多个实例。

真实企业案例:爱彼迎 (Airbnb) 数据建模

  • Airbnb 的类模型使用私有字段来保障安全性:
  • `User` 类: 私有属性 `-ssn` 和 `-passwordHash`,配以公有方法 `+login()`。
  • 多重性关联: 一个房东 `Host` [1] 与房屋 `Listing` [0..*] 类具有“一对多”的关联关系。

参考链接: Airbnb 数据结构建模分析

UML 类图标示规范

图表元素 UML 语法格式 具体定义 / 含义解释 典型代码示例
访问可见性修饰符 - 或 + - 代表私有属性变量;+ 代表公共操作方法 -salesData: double
类属性 (Attributes) 变量名: 数据类型 私有或公有成员变量,规定变量名及类型 +solverName: String
类方法 (Operations) 方法名(形参): 返回值类型 声明类操作方法、参数列表以及返回的数据类型 +runOptimization(vars): double
关系多重性 (Multiplicity) 1, *, 1..* 规定一个类的实例可以与多少个另一个类的实例相关联 1 个模型实例可以关联 1..* 个数据集

面向对象 DSS 开发的核心优势

  • 高度可重用性 (Reusability): 可以通过继承基类模型(如 OptimizationModel)并快速扩展,无需重写底层求解逻辑。
  • 优异的封装性 (Encapsulation): 将具体的数据库 SQL 连接查询细节隐藏在私有类内部,确保系统变动时安全性。

Concept Visualization 概念可视化

Host- hostId: String- taxId: String+ verifyHost()Listing- listingId: String- price: Double+ calculateRent()10..*

Educational Infographic 教学信息图

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

Parent: Model Child: SolverModel

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

📐 UML Class Diagram Syntax & Attributes

Represent object-oriented DSS data entities:

Class Name: DecisionModel - modelID: int - modelType: String + solveOptimization(): double + runSensitivityAnalysis(): Matrix

Tips 提示

Private visibility is represented by a MINUS (-) sign, public by a PLUS (+) sign, and protected by a HASH (#) sign. Multiplicities indicate relationships like 1-to-many (1..*).
私有可见性用减号 (-) 表示,公有用加号 (+) 表示,保护用井号 (#) 表示。多重性表示诸如一对多 (1..*) 之类的关系。

Knowledge Check 知识自测

1. The private visibility modifier in a UML class diagram is represented by which symbol? UML 类图中的私有可见性修饰符用哪个符号表示?

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

2. What relationship multiplicity represents "zero or more"? 哪种关系多重性表示“零个或多个”?

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

3. The class diagram is considered a: 类图被认为是一种:

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

Practical Exercise 实践练习

Task 1: Write a Java class header named 'DecisionModel' that extends 'Model'. 任务 1: 编写一个名为 'DecisionModel' 并继承自 'Model' 的 Java 类头部。

Task 2: Write the Mermaid class declaration block for a class named 'User'. 任务 2: 为名为 'User' 的类编写 Mermaid 类声明块。

Task 3: Excel formula to round cell A1 to exactly 2 decimal places. 任务 3: Excel 公式:将单元格 A1 的值值五入保留 2 位小数。

Revision Guide 复习指南

Revision Checklist:

  • I can write class attributes and operations in standard UML syntax.
  • I understand class diagram association lines and multiplicities (1..*).
  • I can explain encapsulation, inheritance, and polymorphism in a DSS context.

Key Concepts to Remember:

  • UML Class Diagrams & Visibility Modifiers:
    • Class Diagrams: Static structural diagrams displaying classes, at...

Matching Game 配对游戏

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

Class Diagram
Static model showing attributes and class methods显示属性和类方法的静态模型
`-` Private
Attribute accessible only within the declaring class仅在声明类内部可访问的属性
`+` Public
Indicates relationship range from zero to infinity表示从零到无穷大的关系范围
`0..*` Multiplicity
Attribute accessible by any system class任何系统类均可访问的属性