uml - 如何在 UML2 组件图中正确使用端口和接口(interface)

标签 uml component-diagram

我不太了解如何在 UML2 组件图中使用端口、连接器和接口(interface)。

我理解码件可以是物理组件也可以是逻辑组件,接口(interface)也一样吗?例如,一个必需的导入在组件图中变成了一个必需的接口(interface),或者在类图中变成了一个简单的用法?而且我也不理解端口作为交互点的概念:它只是微服务中入口点和导出点的表示吗?

为了理解我做了两个非常典型的应用场景(我是java开发者)。

场景一

一种典型的外观模式,我的客户端应用程序需要通过外观调用多个 Web 服务(rest 或 soap)。

enter image description here

我尝试在组件图中表示:

enter image description here 1a) 这个图表正确吗?

1b) 在客户端和外观组件之间接口(interface)的使用是否正确,或者我只需要一个简单的<>?物理上没有接口(interface),只有一个类导入,但逻辑上什至外观组件也公开了一个 API(不同于 Web 服务 API)。不需要端口,因为客户端和外观不是完全独立的软件,对吗?

1c) 在外观和服务之间我需要端口,因为我们连接到各种独立的软件(可能不是我们的软件)。对吗?

场景 2 现在我做了第二个场景,在 java web 应用程序中也很典型。 出于业务目的需要调用 EJB(具有接口(interface)的远程类)的 MVC 应用程序。

enter image description here

我的组件图:

enter image description here 2a) 在这种情况下,在演示组件中包含我的用户界面,在各种 UI 和整个组件之间建立了委托(delegate)连接。这是正确的使用方法吗?

2b) 表示和业务组件之间是否与场景 1 相同,当我调用 Web 服务并需要使用端口时?

如果我的组件图有误,请帮助我理解我的错误以及如何为这些场景制作正确的组件图。

最佳答案

这几乎没问题。你的Delegate类看起来多余。委托(delegate)是一个更抽象的概念:

enter image description here (抱歉那个粉红色的标签;工具问题)

所以你只要画一个<<delegate>>从端口到组件内部将负责的类、组件或属性的关系。您也可以像以前那样委托(delegate)给内部接口(interface)。


我查阅了 UML 2.5 的授权。在第 189 页:

A delegation Connector is a Connector that links a Port to a role within the owning EncapsulatedClassifier. It represents the forwarding of requests (Operation invocations and Signals). A request that arrives at a Port that has a delegation Connector to one or more Properties or Ports on Properties will be passed on to those targets for handling.

Delegation Connectors can be used to model the hierarchical decomposition of behavior, where services provided by an EncapsulatedClassifier may ultimately be realized by one that is nested multiple levels deep within it.

As a ConnectableElement, the effective provided Interfaces (see 11.2.3) of a Port are its provided interfaces, and the effective required Interfaces are its required Interfaces. However, for a delegating Port, i.e., a Port that is at an end of a delegation Connector and is not on a role and that is not a behavior Port, the effective provided Interfaces are its required interfaces and its effective required Interfaces are its provided interfaces. Consequently a delegating Port behaves, for connection, as though it had an internal “face” that is the conjugate of its external “face.”

If several Connectors are attached on one side of a Port, then any request arriving at this Port on a link derived from a Connector on the other side of the Port will be forwarded on links corresponding to these Connectors. It is not defined whether these requests will be forwarded on all links, or on only one of those links.

该页面上有更多关于端口的信息。

关于uml - 如何在 UML2 组件图中正确使用端口和接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60968466/

相关文章:

java - 类图的替代方案

C#代码到UML图

java - 如何通过签名实现操作

uml - 如何使用 Enterprise Architect 连接 Lollipop - 组件图(装配关系)

architecture - 现代 REST 应用程序是 3 层架构还是 4 层架构?

architecture - 在 UML 组件图中重用子组件

interface - 如何在 UML 组件图中找出组件的正确接口(interface)?

java - 如何在类图中呈现与接口(interface)类有关系的抽象类

java - 这个实现是组合还是聚合?