我们能够扩展一个 UML 接口到多大程度?

huangapple go评论58阅读模式
英文:

How far can we stretch a UML Interface?

问题

首先,背景
我们正在使用quantum leaps的QP Framework开发一些应用程序。
QP基本上是状态机的事件管理器。

我们的方法
因为我们正在使用QP,所以我们的模块与事件和信号(类/结构体和枚举)进行交互,除了一些非常特定的模块,它们通过方法进行交互。

问题
对于那些最后一种模块,接口很容易,只是该模块中的所有公共方法的集合,但其他模块怎么样呢?我们能否说一个接口是其他类和枚举的组合?

由于模块通过发送/接收事件进行交互,因此两者都应该知道可以通过该接口传递什么类型的数据包(事件)。

我们能否像这样表示一个接口?或者接口只应该是一组方法的集合?

编辑1
回应下面的评论,我不想说接口有嵌套类,而是接口将定义这些类,以便它们可以用作事件,但根据您的回答,似乎使用signals会是更好的方法。 (ADC::前缀和接口的名称不同,只是一些糟糕的命名选择,因为包名称是ADC,接口也是ADC)

编辑2
根据下面的评论和答案,我不知道signal的陈述,所以更新问题,我认为它可能会变成这样?

这解决了类和信号的问题,但```enum`仍然存在...

我的意图是说接口将定义这些关键字,即实现接口的模块应该定义这些enum及其值。

这是正确的方法吗?

英文:

First, context:
We're developing some applications using QP Framework from quantum leaps.
QP is basically an event manager for state machines.

Our approach:
Since we're using QP, our modules interact with events and signals (classes/structs and enums) except some very specific modules that interact by methods.

Problem:
For those last modules, interfaces are easy, just a collection of all the public methods in said module, however, how about the others? Can we say an interface is a composition of other classes and enumerations?

Since the modules interact by sending/receiving events, both should know what kind of data packets (events) can travel through that interface.

Can we represent an interface like this? or should an interface only be a collection of methods?
我们能够扩展一个 UML 接口到多大程度?

edit 1:
Replying to the comments below, I don't want to say the interface had nested classes, but that the interface would define said classes so they could be used as events, but from your answers, seems using signals would be a better approach. (The ADC:: prefix and the name of the interface are not the same, just some bad naming choices, as the package name was ADC and so was the interface)

edit 2:
From the comments and answers below, I had no knowledge of the signal stereotype, so updating the question, I think it would become something like this?

我们能够扩展一个 UML 接口到多大程度?

This solves the classes and signals problem, however, the enum remain...

My intention was to say the interface would define this keywords, i.e. the module that implements the interface, should define this enum and their values.

Is this the correct approach?

答案1

得分: 1

你的图中的接口是完全合法的。UML接口不受Java接口的约束:它们可以具有操作、属性和各种关联(顺便说一句,聚合在形式上不会为关联添加任何语义,你可以考虑安全地删除白色菱形),包括组合(黑色菱形)。

然而,它可能不代表你正在寻找的内容:接口表示一个契约。这意味着实现它的类必须提供这些属性和关联,而不是通过某种“继承”方式获取所有这些特性。

此外,我不确定你是尝试表示某种复杂的接口,还是只是找不到更好的表示事件消耗/生成的方法。在后一种情况下,这将是一种过于复杂和具有误导性的方法。

对于基于事件的设计,你可能对使用"信号"感兴趣。信号类似于类,但有用于表示处理一系列事件的能力和/或生成事件的UML元素。此外,它有助于序列图和类图之间的链接,因为消息可以直接对应到事件实例。

英文:

The interface in your diagram is perfectly legit. UML interfaces do not have the constraints of Java interfaces: they can have operations, attributes, and all kind of associations (btw, the aggregation does formally not add any semantics to associations, and you could safely consider to remove the white diamonds), including composition (black diamond).

However it might not represent what you are looking for: interfaces express a contract. It means that the classes implementing it must provide those attributes and associations, and not that the classes will get all these features by a kind of “inheritance”.

Moreover, I’m not sure if you try to express some complex interface, or just found no better way to represent event consumption/generation. In the latter cse it would be an overcomplex and misleading approach.

For event based design, you may be interested in using signals. Signals are like classes, but there are UML elements to express the ability to process a family of events, and/or to generate events. It moreover facilitates the link between sequence diagrams and class diagrams, as a message can correspond directly to an event instance.

答案2

得分: 0

该模型本身是合法的。然而,这可能不是您的本意。共享聚合没有明确定义的含义。请参阅UML 2.5的第110页。

共享 | 表示该属性具有共享聚合语义。共享聚合的精确语义因应用领域和建模者而异。

因此,除非您定义它们的含义,否则该模型没有明确定义的含义。

如果您打算继承操作/属性,可以向其他类绘制一个开放的三角箭头。枚举应该只是一个属性(带有角色的简单关联)。

附言:根据Geert的评论,我也注意到了嵌套。所以您显然过度定义了这一点,添加了(毫无意义的)共享聚合。您可以通过将它们显示在放大的“接口”内来表示嵌套类。或者您可以使用(正如Geert建议的那样)嵌套关系(个人而言,我很少使用它,但这是一种替代方法)。

英文:

The model per se is legit. However, it's likely not what you intended. The shared aggregation has no defined meaning. See p. 110 of UML 2.5

> shared | Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.

So unless you define the meaning of them the model has no defined meaning.

If you intend to inherit operations/attributes you would draw an open triangle arrow towards other classes. Enumerations should simply be an attribute (simple association with role).

P.S. As per Geert's comment I notice the nesting too. So you obviously over-define this by adding the (meaningless) shared aggregation. You could represent the nested classes by showing them inside the enlarged «interface». Or you use (as suggested by Geert) the nesting relation (personally I use that rarely, but it's an alternative).

huangapple
  • 本文由 发表于 2023年2月10日 15:44:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定