在用例图中包含和扩展之间的区别是什么?


当前回答

为了简化,

为包括

当基本用例执行时,包含的用例将每次执行一次。 基本用例需要完成所包含的用例才能完成。

一个典型的例子:在登录和验证密码之间

(登录)——<< include >>——>(验证密码)

为了使登录过程成功,“验证密码”也必须成功。


为扩展

当基本用例被执行时,扩展用例只是偶尔执行 扩展用例仅在满足某些条件时才会发生。

一个典型的例子:在登录和显示错误消息之间(只偶尔发生)

(登录 ) <--- << 扩展> >——(显示错误消息)

“show error message”只在登录过程失败时才会出现。

其他回答

当一个用例有先决条件时,就使用include。

对于有身份验证的用例,最坏的情况,或者是可选的,然后选择extend..

示例:用于寻求入场、预约、机票预订的用例 您必须填写一份表格(注册或反馈表)....这就是包容的由来。

例如:对于验证登录或登录您的帐户的用例,您的身份验证是必须的。还要考虑最坏的情况。比如按时还书,没有预定,逾期付款,这就是延期发挥作用的地方。

不要在图中过度使用include和extend。

保持简单,傻瓜!!

用例用于记录行为,例如回答这个问题。

一种行为延伸了另一种行为,如果它是行为的补充,但不一定是行为的一部分,例如研究答案。

还要注意的是,如果你不试图回答这个问题,研究答案也没有多大意义。

如果一个行为是包含行为的一部分,则该行为被包含在另一个行为中,例如登录到堆栈交换。

为了澄清,只有当你想在堆栈溢出中回答这个问题时,这个例子才成立。

这些是UML 2.5第671-672页的技术定义。

我强调了我认为重要的几点。

扩展

扩展是一个从扩展UseCase(扩展)到扩展UseCase (extendedCase)的关系 如何以及何时将扩展UseCase中定义的行为插入到扩展UseCase中定义的行为中。 扩展发生在扩展的UseCase中定义的一个或多个特定扩展点上。

当有一些额外的行为应该被添加到行为中时(可能是有条件的)使用Extend 定义在一个或多个用例中。

扩展的UseCase的定义独立于扩展的UseCase,并且具有独立于扩展的意义 UseCase。另一方面,扩展的UseCase通常定义了本身不一定有意义的行为。 相反,扩展的UseCase定义了一组模块化行为增量,以增加扩展UseCase的执行 在特定条件下。

...

包括

Include is a DirectedRelationship between two UseCases, indicating that the behavior of the included UseCase (the addition) is inserted into the behavior of the including UseCase (the includingCase). It is also a kind of NamedElement so that it can have a name in the context of its owning UseCase (the includingCase). The including UseCase may depend on the changes produced by executing the included UseCase. The included UseCase must be available for the behavior of the including UseCase to be completely described.

The Include relationship is intended to be used when there are common parts of the behavior of two or more UseCases. This common part is then extracted to a separate UseCase, to be included by all the base UseCases having this part in common. As the primary use of the Include relationship is for reuse of common parts, what is left in a base UseCase is usually not complete in itself but dependent on the included parts to be meaningful. This is reflected in the direction of the relationship, indicating that the base UseCase depends on the addition but not vice versa.

...

我记得是通过电子游戏。例如, (下面不是100%的用例,只是一个用例的例子)

扩展:主菜单扩展了一些功能,这意味着它们有一些功能,但不需要按下

包括:为了在电子游戏中开火,你必须先有一个武器。

我认为msdn在这里解释的很容易理解。

包括[5]

包含用例调用或调用包含的用例。包含用于显示用例如何分解为更小的步骤。所包含的用例位于箭头末端。

扩展[6]

同时,扩展用例将目标和步骤添加到扩展用例中。延期只在特定条件下生效。扩展用例位于箭头末端。

当用例向另一个一级用例添加步骤时,使用Extend。

例如,假设“提取现金”是自动柜员机(ATM)的一个用例。“评估费用”将扩展提现并描述有条件的“扩展点”,该“扩展点”在ATM用户不在ATM所属机构存入银行时实例化。注意,基本的“Withdraw Cash”用例独立存在,没有扩展。

Include用于提取在多个用例中重复的用例片段。被包含的用例不能独立存在,没有被包含的用例原始的用例是不完整的。这应该谨慎使用,并且只在重复很明显并且是故意存在(而不是巧合)的情况下使用。

例如,在每个ATM用例开始时发生的事件流(当用户放入他们的ATM卡,输入他们的PIN,并显示主菜单时)将是一个很好的包含候选。