在用例图中包含和扩展之间的区别是什么?
当前回答
这可能会引起争议,但“包含总是,扩展有时是”是一个非常常见的误解,现在几乎已经取代了事实上的含义。以下是一个正确的方法(在我看来,并与雅各布森、福勒、拉尔曼和其他10个参考文献进行了对比)。
关系是依赖关系
包含和扩展用例关系的关键是要认识到,与UML的其余部分一样,用例之间的虚线箭头是一种依赖关系。我将使用术语“基本”、“包含”和“扩展”来指代用例角色。
包括
A base use case is dependent on the included use case(s); without it/them the base use case is incomplete as the included use case(s) represent sub-sequences of the interaction that may happen always OR sometimes. (This is contrary to a popular misconception about this, what your use case suggests always happens in the main scenario and sometimes happens in alternate flows simply depends on what you choose as your main scenario; use cases can easily be restructured to represent a different flow as the main scenario and this should not matter).
在单向依赖的最佳实践中,基本用例知道(并引用)被包含的用例,但被包含的用例不应该“知道”基本用例。这就是为什么包含的用例可以是:a)它们自己的基本用例和b)由许多基本用例共享。
扩展
扩展用例依赖于基本用例;它从字面上扩展了基本用例所描述的行为。基本用例本身应该是一个完全功能的用例(当然包括了),没有扩展用例的附加功能。
扩展用例可以在以下几种情况下使用:
The base use case represents the “must have” functionality of a project while the extending use case represents optional (should/could/want) behavior. This is where the term optional is relevant – optional whether to build/deliver rather than optional whether it sometimes runs as part of the base use case sequence. In phase 1 you can deliver the base use case which meets the requirements at that point, and phase 2 will add additional functionality described by the extending use case. This can contain sequences that are always or sometimes performed after phase 2 is delivered (again contrary to popular misconception). It can be used to extract out subsequences of the base use case, especially when they represent ‘exceptional’ complex behavior with its own alternative flows.
需要考虑的一个重要方面是,扩展用例可以在基本用例流中的几个地方“插入”行为,而不是像被包含的用例那样只在一个地方插入。由于这个原因,扩展用例不太可能适合扩展多个基本用例。
至于依赖关系,扩展用例依赖于基本用例,同样是单向依赖,即基本用例不需要序列中任何对扩展用例的引用。这并不意味着您不能演示扩展点或在模板的其他地方向扩展用例添加x-ref,而是基本用例必须能够在没有扩展用例的情况下工作。
总结
我希望我已经说明了“包含总是,扩展有时是”的常见误解要么是错误的,要么充其量是简单的。如果你考虑到误解所呈现的箭头方向的所有问题,这个版本实际上更有意义——在正确的模型中,它只是依赖关系,如果你重构用例内容,它不会潜在地改变。
其他回答
图元素
Actors: Also referred to as Roles. Name and stereotype of an actor can be changed in its Properties tab. Inheritance: Refinement relations between actors. This relation can carry a name and a stereotype. Use cases: These can have Extension Points. Extension Points: This defines a location where an extension can be added. Associations: Between roles and use cases. It is useful to give associations speaking names. Dependencies: Between use cases. Dependencies often have a stereotype to better define the role of the dependency. To select a stereotype, select the dependency from the diagram or the Navigation pane, then change the stereotype in the Properties tab. There are two special kinds of dependencies: <<extend>> and <<include>>, for which Poseidon offers own buttons (see below). Extend relationship: A uni-directional relationship between two use cases. An extend relationship between use case B and use case A means that the behavior of B can be included in A. Include relationship: A uni-directional relationship between two use cases. Such a relationship between use cases A and B means, that the behavior of B is always included in A. System border: The system border is actually not implemented as model element in Poseidon for UML. You can simply draw a rectangle, send it to the background and use it as system border by putting all corresponding use cases inside the rectangle.
包含关系允许一个用例包含另一个用例的步骤。
例如,假设你有一个亚马逊账户,你想查看订单,如果不先登录你的账户,就不可能查看订单。所以事件的发展会这样。
扩展关系用于向用例流添加一个额外的步骤,这通常是一个可选的步骤…
假设我们还在谈论你的亚马逊账户。让我们假设基本用例是Order,扩展用例是Amazon Prime。用户可以选择定期订购商品,也可以选择亚马逊Prime,以确保他的订单以更高的成本更快到达。
但是,请注意,用户不必选择Amazon Prime,这只是一个选项,他们可以选择忽略这个用例。
这可能会引起争议,但“包含总是,扩展有时是”是一个非常常见的误解,现在几乎已经取代了事实上的含义。以下是一个正确的方法(在我看来,并与雅各布森、福勒、拉尔曼和其他10个参考文献进行了对比)。
关系是依赖关系
包含和扩展用例关系的关键是要认识到,与UML的其余部分一样,用例之间的虚线箭头是一种依赖关系。我将使用术语“基本”、“包含”和“扩展”来指代用例角色。
包括
A base use case is dependent on the included use case(s); without it/them the base use case is incomplete as the included use case(s) represent sub-sequences of the interaction that may happen always OR sometimes. (This is contrary to a popular misconception about this, what your use case suggests always happens in the main scenario and sometimes happens in alternate flows simply depends on what you choose as your main scenario; use cases can easily be restructured to represent a different flow as the main scenario and this should not matter).
在单向依赖的最佳实践中,基本用例知道(并引用)被包含的用例,但被包含的用例不应该“知道”基本用例。这就是为什么包含的用例可以是:a)它们自己的基本用例和b)由许多基本用例共享。
扩展
扩展用例依赖于基本用例;它从字面上扩展了基本用例所描述的行为。基本用例本身应该是一个完全功能的用例(当然包括了),没有扩展用例的附加功能。
扩展用例可以在以下几种情况下使用:
The base use case represents the “must have” functionality of a project while the extending use case represents optional (should/could/want) behavior. This is where the term optional is relevant – optional whether to build/deliver rather than optional whether it sometimes runs as part of the base use case sequence. In phase 1 you can deliver the base use case which meets the requirements at that point, and phase 2 will add additional functionality described by the extending use case. This can contain sequences that are always or sometimes performed after phase 2 is delivered (again contrary to popular misconception). It can be used to extract out subsequences of the base use case, especially when they represent ‘exceptional’ complex behavior with its own alternative flows.
需要考虑的一个重要方面是,扩展用例可以在基本用例流中的几个地方“插入”行为,而不是像被包含的用例那样只在一个地方插入。由于这个原因,扩展用例不太可能适合扩展多个基本用例。
至于依赖关系,扩展用例依赖于基本用例,同样是单向依赖,即基本用例不需要序列中任何对扩展用例的引用。这并不意味着您不能演示扩展点或在模板的其他地方向扩展用例添加x-ref,而是基本用例必须能够在没有扩展用例的情况下工作。
总结
我希望我已经说明了“包含总是,扩展有时是”的常见误解要么是错误的,要么充其量是简单的。如果你考虑到误解所呈现的箭头方向的所有问题,这个版本实际上更有意义——在正确的模型中,它只是依赖关系,如果你重构用例内容,它不会潜在地改变。
当您理解您的用例过于复杂时,可以使用Extends。因此,您将复杂的步骤提取到它们自己的“扩展”用例中。
Includes用于在两个用例中看到相同的行为。因此,您将常见的行为抽象到一个单独的“抽象”用例中。
(参考:Jeffrey L. Whitten, Lonnie D. Bentley,系统分析与设计方法,McGraw-Hill/Irwin, 2007)
<include>和<extend>都依赖于基类,但<extend>是可选的,也就是说,它是从基类派生的,但在用户的角度来看,它可以被使用,也可以不被使用。
<include>被合并到基类中,也就是说,在用例中必须使用<include>,否则它将被认为是不完整的。
eg:
在ATM机构造上(根据用户角度):
1:提现、存现、支票账户属于<extend>,因为它取决于用户是提现、存款还是支票。这些都是用户可以选择做的事情。
2:“输入pin,放置卡片,移除卡片”这些是在<包括>下的事情,因为用户必须,而且应该,放置卡片并输入有效的pin进行验证。