软件工程

本类阅读TOP10

·PHP4 + MYSQL + APACHE 在 WIN 系统下的安装、配置
·Linux 入门常用命令(1)
·Linux 入门常用命令(2)
·使用 DCPROMO/FORCEREMOVAL 命令强制将 Active Directory 域控制器降级
·DirectShow学习(八): CBaseRender类及相应Pin类的源代码分析
·基于ICE方式SIP信令穿透Symmetric NAT技术研究
·Windows 2003网络负载均衡的实现
·一网打尽Win十四种系统故障解决方法
·数百种 Windows 软件的免费替代品列表
·收藏---行百里半九十

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
正确理解扩展关系和扩展点

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

    在编写用例时,很多人搞不清扩展和扩展点的概念,我也曾为此头痛,经过一段时间摸索才搞明白,所以写了这篇短文与大家共享。

    用例可以扩展(extend)一个已经存在的用例。在扩展用例中,扩展发生在一个特定的点上,被称为扩展点(extension point)。可以把扩展看作是在某一特定情况下将额外的描述文本在扩展点上插入被扩展用例中。扩展主要用来简化复杂的事件流,以表示可选择的行为或处理例外情况。使用扩展建模可以使基本用例更易于理解,使用例模型更易于维护。(摘自《统一软件开发过程引论》P83)
    下面是一个使用了扩展点的用例示范(摘自《有效用例模式》P186~187):
用例7.5 “预订航班”用例
预订航班
1. 当代理人为客户指定旅行路线时,用例开始。
2. 系统搜索一组符合条件的航班,并将他们提供给代理人。
   (飞行常客a)
3. 代理人选择“选择航班”。
4. 系统验证航班上还有座位并预约座位。
   (飞行常客b)
5. 代理人提供支付信息,结束预订。
   (飞行常客c)
6. 系统预订座位并出票。
分支
4a 在选择的票类中没有座位可以提供:
   4a1. 系统通知代理人,在客户选择的票价类别中没有座位可以提供。
   4a2. 代理人指定另一种价格偏好。
4b 没有座位可以提供(航班已满):
   4b1. 系统通知代理人根本没有座位提供。
   4b2. 代理人指定另一组客户的起飞时间偏好。
   (飞行常客d)

用例7.6 “为飞行常客预订航班”用例
为飞行常客预订航班
扩展“预订航班”
飞行常客a
1. 系统检索客户的资料,并显示根据客户的航线偏好进行分类的航班。
飞行常客b
1. 系统为客户提供头等座位。
飞行常客c
1. 系统验证客户已经升级了其账号中的优惠券
2. 系统把客户列入航班升级清单。
分支
没有座位可以提供
飞行常客d
1. 代理人将客户放在一个座位等待优先级清单上。

    RUP的用例规约(Use Case Specification)模板同时具有备选流(Alternative Flows)和扩展点(Extension Points),如下:
2.2 Alternative Flows
2.2.1 < First Alternative Flow >
    [More complex alternatives should be described in a separate section, which is referred to in the Basic Flow subsection of Flow of Events section.  Think of the Alternative Flow subsections like alternative behavior-each alternative flow represents alternative behavior, many times because of exceptions that occur in the main flow.  They may be as long as necessary to describe the events associated with the alternative behavior.  When an alternative flow ends, the events of the main flow of events are resumed unless otherwise stated.]
2.2.1.1 < An Alternative Sub-flow >
    [Alternative flows may, in turn, be broken down into subsections if it improves clarity.]
2.2.2 < Second Alternative Flow >
    [There may be, and most likely will be, a number of alternative flows in a use case.  Keep each alternative separate to improve clarity.  Using alternative flows improves the readability of the use case, as well as preventing use cases from being decomposed into hierarchies of use cases.     Keep in mind that use cases are just textual descriptions, and their main purpose is to document the behavior of a system in a clear, concise, and understandable way.]

6. Extension Points
    [Extension points of the use case.]
6.1 <Name of Extension Point>
    [Definition of the location of the extension point in the flow of events.]
    根据上面所给出的扩展和扩展点的定义,对照用例示范,不难得知:RUP模板中备选流对应用例示范的分支,扩展点是用例示范中扩展点的集中描述。依据模板注释我们可以将用例示范改写成:
用例7.5 “预订航班”用例
预订航班
1. 当代理人为客户指定旅行路线时,用例开始。
2. 系统搜索一组符合条件的航班,并将他们提供给代理人。
3. 代理人选择“选择航班”。
4. 系统验证航班上还有座位并预约座位。
5. 代理人提供支付信息,结束预订。
6. 系统预订座位并出票。
备选流
4a 在选择的票类中没有座位可以提供:
   4a1. 系统通知代理人,在客户选择的票价类别中没有座位可以提供。
   4a2. 代理人指定另一种价格偏好。
4b 没有座位可以提供(航班已满):
   4b1. 系统通知代理人根本没有座位提供。
   4b2. 代理人指定另一组客户的起飞时间偏好。
扩展点
1. 飞行常客
   用例7.6 “为飞行常客预订航班”

    需要注意的是,有一个扩展点就一定有一个扩展用例与之对应。
    总之,备选流和扩展点都是用于表示可选择的行为或处理例外情况,在一些用例描述模板中此二者是放在一起的,而在RUP模板中把它们分开。为什么要分开呢?原因是扩展不同于一般意义上的可选择的行为或处理例外情况,当分支动作路径中断了一个场景中的大量步骤时,创建一个扩展用例是合适的,这就是InterruptAsExtension用例模式。




相关文章

相关软件