The Use Case Model

本文详细介绍了用例模型的概念及其组成部分,包括用例描述、参与者、需求、约束、场景等,并探讨了用例间的包含与扩展关系及序列图的使用。

The Use Case Model


The Use Case Model describes the proposed functionality of the new system. A Use Case represents a discrete unit of interaction between a user (human or machine) and the system. A Use Case is a single unit of meaningful work; for example login to system, register with system and create order are all Use Cases. Each Use Case has a description which describes the functionality that will be built in the proposed system. A Use Case may 'include' another Use Case's functionality or 'extend' another Use Case with its own behaviour.

Use Cases are typically related to 'actors'. An actor is a human or machine entity that interacts with the system to perform meaningful work.

A Use Case description will generally include:

1. General comments and notes describing the use case;
2.Requirements - Things that the use case must allow the user to do, such as <ability to update order>, <ability to modify order> & etc.
3.Constraints- Rules about what can and can't be done. Includes i) pre-conditions that must be true before the use case is run -e.g. <create order> must precede <modify order>; ii) post-conditions that must be true once the use case is run e.g. <order is modified and consistent>; iii) invariants: these are always true - e.g. an order must always have a customer number
4.Scenarios - Sequential descriptions of the steps taken to carry out the use case. May include multiple scenarios, to cater for exceptional circumstances and alternate processing paths;
5.Scenario diagrams -Sequence diagrams to depict the workflow - similar to (4) but graphically portrayed.
6.Additional attributes such as implementation phase, version number, complexity rating, stereotype and status

Actors
An Actor is a user of the system. This includes both human users and other computer systems. An Actor uses a Use Case to perform some piece of work which is of value to the business. The set of Use Cases an actor has access to defines their overall role in the system and the scope of their action.

Constraints, Requirements and Scenarios

The formal specification of a Use Case includes:

1. Requirements. These are the formal functional requirements that a Use Case must provide to the end user. They correspond to the functional specifications found in structured methodologies. A requirement is a contract that the Use Case will perform some action or provide some value to the system.
2.Constraints. These are the formal rules and limitations that a Use Case operates under, and includes pre- post- and invariant conditions. A pre-condition specifies what must have already occurred or be in place before the Use Case may start. A post-condition documents what will be true once the Use Case is complete. An invariant specifies what will be true throughout the time the Use Case operates.
3.Scenarios. Scenarios are formal descriptions of the flow of events that occurs during a Use Case instance. These are usually described in text and correspond to a textual representation of the Sequence Diagram.

Includes and Extends relationships between Use Cases
One Use Case may include the functionality of another as part of its normal processing. Generally, it is assumed that the included Use Case will be called every time the basic path is run. An example may be to list a set of customer orders to choose from before modifying a selected order - in this case the <list orders> Use Case may be included every time the <modify order> Use Case is run.

A Use Case may be included by one or more Use Cases, so it helps to reduce duplication of functionality by factoring out common behaviour into Use Cases that are re-used many times.
One Use Case may extend the behaviour of another - typically when exceptional circumstances are encountered. For example, if before modifying a particular type of customer order, a user must get approval from some higher authority, then the <get approval> Use Case may optionally extend the regular <modify order> Use Case.

Sequence Diagrams
UML provides a graphical means of depicting object interactions over time in Sequence Diagrams. These typically show a user or actor, and the objects and components they interact with in the execution of a use case. One sequence diagram typically represents a single Use Case 'scenario' or flow of events.
Sequence diagrams are an excellent way to document usage scenarios and to both capture required objects early in analysis and to verify object usage later in design. Sequence diagrams show the flow of messages from one object to another, and as such correspond to the methods and events supported by a class/object.
The diagram illustrated below shows an example of a sequence diagram, with the user or actor on the left initiating a flow of events and messages that correspond to the Use Case scenario. The messages that pass between objects will become class operations in the final model.


Implementation Diagram
A Use Case is a formal description of functionality the system will have when constructed. An implementation diagram is typically associated with a Use Case to document what design elements (eg. components and classes) will implement the Use Case functionality in the new system. This provides a high level of traceability for the system designer, the customer and the team that will actually build the system. The list of Use Cases that a component or class is linked to documents the minimum functionality that must be implemented by the component.

The example above shows that the Use Case "Login" implements the formal requirement "1.01 Log on to the website". It also states that the Business Logic component and ASP Pages component implement some or all of the Login functionality. A further refinement is to show the Login screen (a web page) as implementing the Login interface. These implementation or realisation links define the traceability from the formal requirements, through Use Cases on to Components and Screens.

 
<think>好的,我现在需要帮助用户了解如何使用EA工具绘制简易在线翻译器系统的UML用例图以及相关的最佳实践。首先,我得回顾一下用户之前的提问历史。用户之前已经询问过如何绘制类图和顺序图,现在转向用例模型,可能希望补充系统的高层功能视图。 用户的需求很明确,但需要确保用例图能够准确反映系统的功能,同时符合最佳实践。用户可能对UML的基本概念有一定了解,但需要具体的步骤指导和EA操作技巧。考虑到用户之前使用EA的经验,应该详细说明工具的具体操作,比如如何创建用例、参与者,以及如何建立关系。 接下来,我需要思考用例图的基本组成部分:参与者、用例、关系(包含、扩展、泛化)。对于在线翻译器来说,主要参与者可能是用户和可能的第三方翻译服务。用例可能包括输入文本、选择语言、翻译文本、显示结果、处理错误等。 需要提醒用户注意用例的粒度,避免过于宽泛或过于琐碎。比如,“翻译文本”是一个合适的用例,而分解成“输入文本”和“点击翻译按钮”可能太细。同时,最佳实践包括使用包含关系来复用公共用例,比如验证输入可能被多个用例包含。 在EA工具的操作步骤方面,用户需要知道如何创建模型、添加用例图、拖拽元素、设置关系等。可能还需要指导如何添加注释或约束,以及如何保持图的整洁和可读性。例如,使用布局工具自动排列元素,避免交叉线。 此外,用户可能对如何识别参与者感到困惑。需要建议他们从系统外部交互的对象出发,比如普通用户、管理员、外部API等。但根据“简易”系统的描述,可能只需要考虑用户和翻译引擎。 最后,需要总结注意事项,比如保持用例的独立性,使用正确的关系类型,以及如何验证用例图是否完整。可能还需要提到与之前类图和顺序图的一致性,确保整个模型协调。 现在要组织这些思考,按照步骤和最佳实践结构化回答,确保用户能够逐步跟随操作,同时理解背后的设计原则。还要注意引用之前的回答,保持连贯性,比如提到类图中的TranslationEngine类如何对应到用例中的翻译服务。</think>#### 如何用EA绘制简易在线翻译器系统的UML用例图与最佳实践 --- ### 一、用例图核心要素设计 1. **识别参与者** - **主要参与者**:普通用户(翻译请求者)、管理员(可选,若需管理翻译引擎) - **外部系统**:第三方翻译API(如Google Translate API)[^4] 2. **定义关键用例** ```plaintext |-------------------------| |-------------------------| | <<actor>> | | <<actor>> | | 用户 | | 翻译服务API | |-------------------------| |-------------------------| | ▲ | 输入翻译文本 | 调用服务 | 选择目标语言 | | 查看翻译结果 | ▼ | |-------------------------| |-------------------------| | <<用例>> |-----| <<用例>> | | 执行文本翻译 | | 调用外部API | |-------------------------| |-------------------------| ▲ | <<include>> |-------------------------| | <<用例>> | | 验证输入格式 | |-------------------------| ``` --- ### 二、EA工具操作步骤(以v15为例) 1. **创建用例模型** - 新建包 → 右键选择 **Add Diagram → UML Behavioral → Use Case** - 建议命名规范:`UC_OnlineTranslator` 2. **绘制基础元素** - **添加参与者**:工具栏选择 **Actor** 图标,双击命名(如"用户") - **插入用例**:使用 **Use Case** 工具绘制核心功能(如"执行文本翻译") - **关联关系**: - 用 **Association** 连接参与者与用例 - 用 **Include/Extend** 表示包含/扩展关系(右键连线选择构造型) 3. **高级功能设置** - **添加用例规约**:双击用例 → Notes栏填写前置/后置条件 ```plaintext [用例:执行文本翻译] 前置条件:用户已选择目标语言 后置条件:翻译结果存入临时缓存 ``` - **分层展示**:通过 **Package** 分模块(如"用户交互层"、"服务调用层") --- ### 三、最佳实践指南 1. **粒度控制原则** - 单个用例应完成独立业务目标(如"执行翻译"包含输入文本、选择语言、获取结果) - 避免碎片化(如不单独拆分"点击翻译按钮"为用例)[^5] 2. **关系运用技巧** - **«include»**:用于必选子流程(如翻译必须包含"验证输入格式") - **«extend»**:处理可选分支(如"重试失败翻译"扩展主用例) - 示例: ```plaintext <<extend>> (执行文本翻译) <───── (重试失败翻译) ▲ | <<include>> └───── (验证输入格式) ``` 3. **可视化优化** - 使用 **Auto Route** 自动调整连线路径(Diagram → Layout → Auto Route) - 通过 **Boundary** 元素划分系统边界(如区分用户操作与API调用区域) --- ### 四、常见问题解决方案 1. **用例冲突检测** - 使用EA的 **Consistency Checker**(Tools → Data Quality → Run Checks)识别未连接的用例 2. **复杂场景建模** - 对多语言支持场景,可添加泛化关系: ```plaintext <<用例>> 翻译文本 △ ┌─────┴─────┐ <<用例>> <<用例>> 英译中 中译英 ``` 3. **与类图关联** - 在EA中通过 **Traceability** 窗口将用例与类图功能模块绑定(如"执行翻译"用例关联`TranslationEngine`类) --- ### 五、成果输出建议 1. **分层导出**: - 业务视图(仅展示用户可见用例) - 技术视图(包含API交互细节) 2. **动态验证**: - 使用 **Scenario** 功能模拟用例流程(右键用例 → New Child Diagram → Activity) ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值