UML Port
A port specifies an interaction point through which a classifier can communicate with its environment, with other classifiers, or with its internal parts. Encapsulated classifier is defined in UML as structured classifier with the ability to own ports, and thus port is a property of an encapsulated classifier. Port by default has public visibility.
Port is shown as a small square placed either overlapping the boundary of the rectangle denoting the encapsulated classifier, or it may be shown inside that rectangle symbol. The name of the port is placed near the small square.
Library Services class has port searchPort.
While UML does not dictate naming convention for ports, common sense is to start port names from lower case, e.g. "p", "port12", "searchPort". It is unclear, whether each port is required to have a name. If port does have a name, it may be suppressed on a diagram. UML 2.5 specification provides some strange clarification that "every depiction of an unnamed Port denotes a different Port from any other Port." If name of a port was simply suppressed, every depiction of that port should be still the same port.
The type of a port may be shown after the port name, separated by colon ":".
Library Services class has port searchPort with SearchBooks type.
Multiplicity of a port (if any) is shown after the port name in square brackets. Both name and multiplicity of port are optional.
Library Services class has 1 to 6 searchPort ports.
A provided interface may be shown using the "lollipop" notation attached to the port. A required interface may be shown using the "socket" notation attached to the port.
Port searchPort provides SearchBooks and SearchVideo
interfaces and requires Inventory interface.
At the search Port, the Library Services class is completely encapsulated - it can be implemented without any knowledge of the environment the class will be embedded in.
If there are multiple interfaces associated with a port, these interfaces may be listed separated by comma "," near the single interface icon.
Several searchPort ports provide SearchBooks and SearchVideo
interfaces and require Inventory interface.
Port may also be shown as a small square symbol overlapping the boundary of the rectangle symbol denoting a part typed by that classifier.
Simple Port
A simple port is a port with a single required or provided interface. A complex port has several provided and/or required interfaces.
SearchEngine component has simple port searchPort
with single provided ProductSearch interface.
Within a structured classifier UML allows several alternative notations for connecting simple ports on the parts and roles.
The only mandatory notation for connecting ports in an internal structure is when the connector is joined directly to the ports. Optional lollipop and socket could show provided and required interfaces of the connected ports.
Simple ports joined directly by connector, mandatory UML notation.
Customers component part provides Account interface to Orders part.
As an option, UML allows connector line to be attached to the ball and socket instead of ports, as shown below.
Ball and socket joined by connector, optional UML notation.
Customers component part provides Account interface to Orders part.
Assembly connector is not rendered in another optional, "ball-and-socket" notation for simple ports. This notation should not be used to connect complex ports or parts without ports.
"Ball-and-socket" assembly connection for simple ports, optional UML notation.
Customers component part provides Account interface to Orders part.
Service Port
A port may specify the services an encapsulated classifier provides to its environment as well as the services that an encapsulated classifier requires of its environment. Any port is service port by default, which is specified by default true value of isService attribute of the port.
The provided interfaces of a port describe requests to the classifier that other classifiers may make through this port. The required interfaces of a port describe the requests that may be made from the classifier to its environment through the port.
When isService attribute of a port is set to false, it means that this port belongs to the implementation of the encapsulated classifier, and it is not part of the service contract or essential externally visible functionality. Such non-service port could be modified or removed without any effects on service contract. UML specification provides no explanation why this attribute is needed, if we can just change default public visibility of port to e.g. private visibility. Private properties are not part of any externally visible functionality.
UML provides no specific notation to visually distinguish service ports from non-service ports, while it has some convention to render Boolean attributes as property modifiers. For example, {ordered} means that 'isOrdered' attribute is true, while {unordered} means that corresponding property is not ordered. We can probably use the same convention for isService attribute of port, rendering it as either {service} or {nonservice}.
Port actPort is by default a service port providing Orders and
Customers interfaces and requiring Inventory interface.
Behavior Port
Behavior port is a port such that requests arriving at this port are sent to the behavior of the classifier owning the port, rather than being forwarded to some contained instances. If there is no behavior defined for this classifier, any communication arriving at the behavior port is lost. By default, ports are not behavior ports.
A behavior port is rendered as a port connected by a solid line to a small state symbol drawn inside the classifier containing the port. The small state symbol denotes the behavior of the containing classifier.
Port searchPort is behavior port with SearchBooks provided interface.