How to correctly use port and interfaces in a UML2 component diagram

99封情书 提交于 2020-06-27 17:31:30

问题


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?

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

Scenario 1

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) is this diagram correct?

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) Between Facade and Services I need ports because we connect to various indipendent pieces of software (maybe not event our software). Is right?

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.

My component diagram:

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) 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.


回答1:


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.


I looked up UML 2.5 for delegation. On p.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.

There's more about ports around that page.



来源:https://stackoverflow.com/questions/60968466/how-to-correctly-use-port-and-interfaces-in-a-uml2-component-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!