正确理解扩展关系和扩展点

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

    用例可以扩展(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用例模式。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值