如何显示UML中的接口和类之间的关系? [英] How to show relation between interfaces and classes in UML?

查看:71
本文介绍了如何显示UML中的接口和类之间的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些要在UML中表示的相关接口和类(对关系感到抱歉,我不知道如何使用StarUML正确地做到这一点):

I have some related interfaces and classes that I want to represent in UML (sorry about the relationships, I don't know how to do it properly with StarUML):

ISMS实现IMessage和IStorable接口的想法,不是让SMS类直接实现两个接口,而是使项目更具模块化,可维护性和易于测试.

The idea of an interface ISMS implementing IMessage and IStorable, instead of having directly the SMS class implementing itself both interfaces, aims to make the project more modular, maintainable, and easier to test.

这是设计的好方法吗?如果是这样,这是在UML类图中表示它们的一种好方法,还是有一种更好的方法来表示接口及其与UML中其他接口/类的关系?

Is this a good approach for the design? If so, is this a good way of representing them in an UML Class Diagram or is there a better way to represent an interface and its relationship with other interfaces/classes in UML?

推荐答案

Bruno已经很清楚的地方,我有几点评论答案.

接口分解为 IStorable IMessage 乍一看似乎是

The decomposition of the interfaces into IStorable and IMessage seems at first sight to be a sound application of interface segregation principle.

将这两个接口组合成可重用的 ISMS 接口,而不是直接在具体的 SMS 类中实现它们,因为这将使您的代码更易于维护允许用另一种替代SMS实施(如果您认为SMS功能可能是特定于平台的,这是很有意义的.)

Combining the two interfaces into a reusable ISMS interface instead of directly implementing them in a concrete SMS class will in this regard keep your code more maintainable, since it will easily allow to replace the SMS implementation with an alternative one (which makes sense if you consider that SMS functionality can be platform specific).

但是问题是,是否不能互换使用 SMS email .但是只有您可以回答以下问题:如果您的设计要求保持这些通信渠道的截然不同(也许您的实际代码在两个接口之间添加了一些区别),那就很好了.但是,如果不能,那么就应该允许这种互换性,并用一个更通用的 INotification 替换 ISMS IEmail .

The question is however if SMS and email could not be used interchangeably. But only you can answer this question: If your design requires to keep those communication channels distinct (and maybe your real code adds some differences between the two interfaces), it's fine. But if not, it would make sense to allow such interchangeability and replace ISMS and IEmail with a single more general INotification.

首先,我想强调Bruno关于泛化(普通行)与实现(虚线).

First of all, I'd like to reinforce Bruno's remark about the difference between generalization (plain line) and realization (dotted line).

也许我是老学校了,但是我建议不要使用更常规的接口,以及在接口名称上方带有关键字«interface»的类框.尤其是如果您具有属性和操作.

Maybe I'm old school, but instead of using the circle for the interface, I'd advise for the more conventional interface as with a class box with the keyword «interface» above the name of the interface. Especially if you have properties and operations.

在我看来,圆圈更适合界面的棒棒糖符号.当您对接口本身无话可说,但想显示一个类实现(lollipop)或依赖于(socket)的接口时,这是非常实用的.然后在另一个更详细的图中定义接口的详细信息.从理论上讲,您可以将两个符号合并在同一张图中,但就我个人而言,我认为它的可读性较差,因此不建议这样做.

The circle is in my view better suitable for the lollipop notation of an interface. This is very practical when you have no much to say about the interface itself, but want to show what interfaces a class implements (lollipop) or is dependent on (socket). The interfaces details are then defined in another more detailed diagram. You can theoretically merge the two notations in the same diagram, but personally I find it less readable and would not advise it.

这篇关于如何显示UML中的接口和类之间的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆