如何在 UML2 组件图中正确使用端口和接口 [英] How to correctly use port and interfaces in a UML2 component diagram

查看:62
本文介绍了如何在 UML2 组件图中正确使用端口和接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I haven't understood well how to use port, connector and interfaces in a UML2 component Diagram.

我知道组件可以是物理或逻辑组件,接口也一样吗?例如,必需的导入成为组件图中的必需接口或类图中的简单用法?而且我也不明白端口作为交互点的概念:是否只是微服务中进入和退出点的表示?

I understand that a component can be a physical or a logical component, is the same with interfaces? For example a required import becomes a required interface in component diagram or a simple usage as in class diagram? And also I don't understand the concept of a port as an interaction point: is only a representation of enter and exit point in amicroservice?

为了理解我在应用程序中制作了两个非常典型的场景(我是一名 Java 开发人员).

To understand I've made two very typical scenarios in applications (I'm a java developer).

场景一

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

A typical facade pattern where my client application needs to call several web services (rest or soap) through a facade.

我尝试在组件图中表示:

I try to represent in a component diagram:

1a) 这个图是否正确?

1a) is this diagram correct?

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

1b) Between Client and facade component is the use of interfaces correct or I only need a simple <>? Phisically ther's no interface, but only a class import, but logically even the facade component expose an API (different from web service API). Port is not needed because client and facade are not pieces of software totally indipendent, am I right?

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

1c) Between Facade and Services I need ports because we connect to various indipendent pieces of software (maybe not event our software). Is right?

场景 2现在我在 Java Web 应用程序中创建了第二个场景,这也是非常典型的.出于业务目的需要调用 EJB(具有接口的远程类)的 MVC 应用程序.

Scenario 2 Now I made a second scenario also very typical in a java web application. An MVC application that need to call an EJB (a remote class with an interface) for business puroposes.

我的组件图:

2a) 在这种情况下,一个包含在演示组件中的我的 userInterfaces 在各种 UI 和整个组件之间建立了委托连接.这是正确的使用方式吗?

2a) In this case a enclosed my userInterfaces in a presentation component a made a delegation connection between various UI and the entire component. Is this the right way to use it?

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

2b) Between presentation and business component is the same situation of scenario1 when a I call the web services and the use of the port is needed?

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

If my component diagrams are wrong, please help me understand my errors and how to make a correct component diagrams for those scenarios.

推荐答案

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

This is almost ok. Your Delegate class looks superfluous. Delegation is a more abstract concept:

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

(sorry for that pinkish label; tool issue)

因此,您只需绘制从端口到组件内部将负责的类、组件或属性的 <<> 关系.您也可以像以前一样委托给内部接口.

So you just draw a <<delegate>> relation from the port towards the class, component or property which inside the component will take responsibility. You can also delegate to internal interfaces as you did.

我为委托查找了 UML 2.5.在第 189 页:

I looked up UML 2.5 for delegation. On p.189:

委托连接器是将端口链接到拥有 EncapsulatedClassifier 中的角色的连接器.它代表请求的转发(操作调用和信号).到达具有一个或多个属性或属性上的端口的委托连接器的端口的请求将被传递到这些目标进行处理.

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.

委托连接器可用于对行为的分层分解进行建模,其中 EncapsulatedClassifier 提供的服务最终可能由嵌套在其中的多个级别深入实现.

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.

作为一个ConnectableElement,一个Port的有效提供接口(见11.2.3)就是它提供的接口,有效的所需接口就是它需要的接口.但是,对于委托端口,即位于委托连接器末端且不处于角色且不是行为端口的端口,有效提供的接口是其所需的接口,其有效的所需接口是其提供的接口.因此,一个委托端口的行为,对于连接来说,就好像它有一个内部面",它是其外部面"的共轭.

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.

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

There's more about ports around that page.

这篇关于如何在 UML2 组件图中正确使用端口和接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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