如何在 UML 中对使用一个接口作为另一个接口的方法的参数进行建模?
我正在使用 Visual Paradigm for UML 来建模我们的类层次结构。我经常遇到这样的情况:我们的一个接口有一个方法,需要实现另一个接口作为方法的参数。示例(C++,接口=抽象类):
class IFoo {
public:
virtual void bla() = 0;
};
class IBar {
public:
virtual void meep(IFoo &) = 0;
};
我对两个接口进行建模没有问题,但我想知道使用哪种类型的关联来直观地表示这两个接口的关系。目前我正在使用 Visual Paradigm 提供的 Usage
关系,但我不确定这是否确实适用于这种情况。这是正确的使用关系吗?如果不是,我该如何建模这种关系?
I am using Visual Paradigm for UML to model our class hierarchy. I often have the case where one of our interfaces has a method requires an implementation of another of our interfaces as parameter to a method. Example (C++, interface = abstract class):
class IFoo {
public:
virtual void bla() = 0;
};
class IBar {
public:
virtual void meep(IFoo &) = 0;
};
I have no problem modeling both interfaces, but I am wondering which type of association to use for visually representing the relation of these two interfaces. Currently I am using the Usage
-relation provided by Visual Paradigm, but I am not sure if this is indeed intended for this scenario. Is this the correct relation to use? If not, how can I model this relationship?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少在类图中没有正在发生的事情的视觉表示。
我猜您建议的
Usage
会使其成为某种“元”信息。另一种方法是在用例图中指定它。但这也是我所说的“带外”或元级别,因为用例通常仅用于传达记录某些内容的温暖、蓬松的感觉......At least in a class diagram there is no visual representation of what's going on.
The
Usage
that you suggested would make it some kind of "meta" information, I guess. An alternative would be to specify it in a Usecase diagram. But that'd also be what I'd call "out-of-band" or on the meta-level, as Usecases are usually only used to communicate a warm, fluffy feeling of having documented something...您可以使用从具有依赖操作的接口指向在操作中用作参数的接口的依赖关系箭头。然后,您可以通过在接口模型元素中提供依赖操作的完整签名来对依赖关系的细节进行建模。
如果您想提供更多描述依赖关系性质的详细信息,您可以在依赖关系箭头上附加注释。
使用您的示例:
You can use a dependency arrow pointing from the interface with the dependent operation to the interface used as a parameter in the operation. You can then model the specifics of the dependency by providing the full signature of the dependent operations in your interface model element.
If you wanted to provide even more detail describing the nature of the dependency, you could attach a note to the dependency arrow.
Using your example: