英文:
extends in Use Cases diagram
问题
在书中《UML @ Classroom:面向对象建模入门》中写道:“用例——即使是包含或扩展用例——始终可以独立执行。如果它们只能在另一个用例的范围内执行,而不能独立执行,那么它们就不是用例,不应该被描述成用例。它们的功能应该在使用它们的用例的描述中进行覆盖。”然而,我的教授提供给我的所有扩展关系的示例以及我在互联网上找到的扩展用例都只能在基本用例的范围内触发。我感到困惑,哪一个是正确的?
我有一个小项目,我忽略了那些不能被任何参与者触发的扩展用例,我应该绘制这些扩展用例吗?
英文:
in the book UML @ Classroom An Introduction to Object-Oriented Modeling is written "Use cases—even included or extending use cases—can always be executed independently. If they can only be executed within the scope of another use case and not independently, they are not use cases and must
not be depicted as such. Their functionality must then be covered in the
description of the use case that uses them.", however all examples of extends relationships my Professor gave to me and I found in internet the extending use cases can only be triggered within the scope of the base use case.
I'm lost, which one is correct ?
I have a mini-project, I ignored the extending use cases that can't be triggered by any actor, should I draw these extending use cases ?
答案1
得分: 2
规范中提到:
扩展UseCase通常定义的行为本身可能并不一定有意义。
和
扩展发生在扩展UseCase中定义的一个或多个特定扩展点上。
所以,uml@classroom是错误的,你的教授是正确的。扩展用例本身没有意义,并且在扩展用例中没有扩展点就不能存在。
然而,避免使用扩展关系有很好的理由。
首先,规范与自己的定义相矛盾:
UseCase指定由其主体执行的一组操作,产生一个对一个或多个主体的_有价值的_可观察结果或其他利益相关者。
一个可能不一定有意义的行为怎么可能是_“有价值的”_呢?
所以,也许UML应该为此引入_“次要”_ “用例”。实际上,在我们公司就是这样做的。也就是说,如果客户坚持使用_“扩展”或“包含”_。
在我看来,只有在没有其他方式描述常见或扩展行为时,才需要次要_“用例”_。然而,通常情况下,你会使用其他元素来描述用例,比如活动图或交互概述图。它们可以轻松而准确地描述这种行为。扩展用例只会重复努力,没有任何好处。
所以,即使uml@classroom在形式上不正确,建议是合理的!一个值得付出努力的用例是独立的!
附言:很多混淆都来自粗糙的语言使用:用例不_“执行”。用例在我通过调用系统的某些功能来使用系统时“发生”_,然后这些功能将被执行。规范从未使用这种措辞。相反,它谈到了启动用例。
英文:
The specification says:
> the extending UseCase typically defines behavior that may not
> necessarily be meaningful by itself.
and
> The extension takes place at one or more specific extension points
> defined in the extended UseCase.
So, uml@classroom is wrong and your professor is right. Extending use cases are not meaningful by itself and cannot exist without an extension point in the extended case.
However, there are good reasons for avoiding the extend relationship.
First of all, the specification contradicts its own definition:
> A UseCase specifies a set of actions performed by its subjects, which
> yields an observable result that is of value for one or more Actors or
> other stakeholders of each subject.
How can a behavior that "may not necessarily be meaningful" be "of value"?
So, maybe the UML should have introduced «secondary» "use cases" for this purpose. Actually, this is how it is done in my company. That is, if the client insists on using «extend» or «include».
In my opinion secondary "use cases" are only needed, if they are your only means to describe common or extending behavior. However, usually you will use other elements to describe the use case, such as activity diagrams or interaction overview diagrams. They can easily and accurately describe such behavior. Extending use cases will simply duplicate the effort without any benefit.
So, even when uml@classroom is formally incorrect, the advice is sound! A use case that is worth the effort is independent!
PS: Much confusion stems from the sloppy use of language: A use case is not executed. A use case happens, when I use a system by invoking some its functions, which will then get executed. The specification never uses this wording. Rather it talks about initiating a use case.
答案2
得分: 1
独立性是避免功能分解的实际方法。考虑到功能分解并不是一种不好的用例实践(即使 UML 规范明确允许它),寻找独立的用例是个好主意。
扩展也应遵循这一规则,但原因与你想的不同。根据定义,扩展是一种附加行为,只在扩展用例的上下文中才有意义:
UML 2.5.1 - 第18.1.3.2节:扩展是从扩展用例(扩展)到扩展用例(扩展用例)的关系,指定了如何以及何时可以将扩展用例中定义的行为插入到扩展用例中定义的行为中。扩展发生在扩展用例中定义的一个或多个特定扩展点。
扩展旨在在一个或多个用例中定义的行为中添加一些附加行为时使用。因此,很难有独立的扩展。尽管如此,你仍然应用你的书中的规则:避免依赖性用例。因此,最好完全避免扩展。这是个好主意,因为通常扩展呈现的内容可以在扩展用例的叙述中很好地解释。
英文:
The independence is a practical way to avoid functional decomposition. Considering that functional decomposition is not a bad use-case practice (even if UML specs explicitly allow it), it is a good idea to look for independent use-cases.
Extensions should also follow this rule, but not for the reason you think. By definition, the extension is an additional behavior that makes sense only in the context of the extended use-case:
> UML 2.5.1 - Section 18.1.3.2: An Extend is a relationship from an extending UseCase (the extension) to an extended UseCase (the extendedCase) that specifies how and when the behavior defined in the extending UseCase can be inserted into the behavior defined in the extended UseCase. The extension takes place at one or more specific extension points defined in the extended UseCase.
Extend is intended to be used when there is some additional behavior that should be added, possibly conditionally, to the behavior defined in one or more UseCases.
It is therefore very difficult to have an independent extensiin. Nevertheless, still you shoukd apply the rule of your book: avoid dependent use-cases. Therefore avoid extensions at all. And this is good, because most often extznsions present something very detailed that could as well be explained in the narrative of the extended use-case
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论