细小UML考点

1. 系统顺序图(SSD)

(for one particular scenario of a use case , the events that external actors generate , their order , and inter-system events. )

Purpose:
• 表示特定场景下参与者与系统之间的交互。
• 关注与系统相关的输入和输出事件。

Key Features:
Actors: 与系统交互的外部实体。
System: 被建模系统的边界。
Events: 参与者与系统之间交换的消息(输入/输出)。

Example Use Case:
• 对于“用户登录”场景,SSD显示事件序列:

  1. 用户输入凭据。
  2. 系统验证凭据。
  3. 系统授予访问权限。

2. 交互图

(for finish a task showing how several objects collaborate in single use case)

Purpose:
• 显示对象如何在单个用例中协作以完成任务。

Types:

  1. 顺序图:
    • 强调对象之间消息传递的时间顺序。
  2. 通信图:
    • 关注对象群的结构及其消息交互。

Key Features:
Objects: 表示为生命线(顺序图)或节点(通信图)。
Messages: 表示为对象之间的箭头。

Example Use Case:
• 对于“处理订单”用例,交互图显示Order、Payment和Inventory等对象如何协作。


3. 状态机图

(for finish a task showing how several objects collaborate in single use case)

Purpose:

  1. 描述在用例上下文中由系统操作者识别和处理的外部系统事件。
  2. 显示对象在其生命周期内的行为。

Key Features:
States: 表示对象在特定时间点的条件。
Transitions: 表示由事件触发的从一个状态到另一个状态的移动。

Example Use Case:
• 对于“Order”对象,状态机图显示状态如“Pending”、“Shipped”和“Delivered”,以及转换如“Payment Received”或“Order Shipped”。


4. 活动图

Purpose:
• 分析用例、理解涉及多个用例的工作流、处理多线程应用。

Key Features:
Activities: 表示过程中的步骤或任务。
Decisions: 表示流程中的分支条件。
Parallel Activities: 表示可以同时执行的任务。

Example Use Case:
• 对于“处理订单”流程,活动图显示步骤如“接收订单”、“验证库存”和“发货”。


5. 职责分配原则:最小化依赖

Purpose:
• 通过减少对象之间的依赖关系,提高系统的灵活性和可维护性。

Key Measures:
高内聚: 将相关职责集中在一个对象中。
低耦合: 减少对象之间的直接依赖,使用接口或抽象类隔离变化。

Example Use Case:
• 在“处理订单”用例中,将库存管理职责分配给Inventory对象,而不是让Order对象直接依赖库存系统。

1. 依赖(Dependency)

Definition:
• 描述对象之间通过变量或静态方法的依赖关系。
• A依赖B,意味着A使用了B的某些功能。

Examples:

  1. A接收B类对象作为参数:
    1
    2
    3
    4
    5
    public class A {  
    public void process(B b) {
    // A depends on B
    }
    }
  2. A调用B类的静态方法:
    1
    2
    3
    4
    5
    public class A {  
    public void doSomething() {
    B.staticMethod(); // A depends on B
    }
    }

Example Question:
Dependency association between the 2 classes described in Java below:

1
2
3
4
5
6
7
8
9
public class A {  
private ArrayList<B> _Bs = new ArrayList<>();
public A(B _Bs) {
this._Bs.add(_Bs);
}
}
public class B {
// ...
}

Answer:
A depends on B because A uses B as a parameter in its constructor.


2. 组合(Composition)

Definition:
• 表示强整体-部分关系,部分不能独立于整体存在。

Three Rules:

  1. 部分不能同时属于多个整体:
    • 例如,一个手指不能同时属于两只手。
  2. 部分不能游离存在:
    • 例如,手指不能脱离手而存在。
  3. 整体负责部分的创建和删除:
    • 例如,手负责创建和删除手指。

Example:

1
2
3
4
5
6
7
8
9
10
11
public class Hand {  
private List<Finger> fingers = new ArrayList<>();
public Hand() {
for (int i = 0; i < 5; i++) {
fingers.add(new Finger());
}
}
}
public class Finger {
// ...
}


3. 聚合(Aggregation)

Definition:
• 表示弱整体-部分关系,部分可以独立于整体存在。

Example:
• 车有4个轮子,轮子可以独立于车存在。

1
2
3
4
5
6
7
8
9
public class Car {  
private List<Wheel> wheels = new ArrayList<>();
public Car(List<Wheel> wheels) {
this.wheels = wheels;
}
}
public class Wheel {
// ...
}


4. 继承(Inheritance)

Definition:
• 表示“is a”或“is a kind of”关系。

Example:
• 狗是一种动物。

1
2
3
4
5
6
public class Animal {  
// ...
}
public class Dog extends Animal {
// ...
}


5. 用例与补充规约

Use Case:
• 描述系统的功能性需求。
• 例如,用户登录系统。

Supplementary Specification:
• 描述系统的非功能性需求。
• 例如,系统响应时间应小于2秒。

Example:
Use Case: 用户登录。
Supplementary Specification: 系统应在高并发情况下保持稳定。