Skip to content

Port

A port is a place where a structured classifier meets the outside world. A structured classifier is a UML element, such as a class or component, that is built from internal parts. The port connects it to those parts and to its environment.

Where it sits. Public ports are visible to the environment. In a diagram, they are drawn straddling the boundary of the owner.

What it carries. A port is linked to interfaces. The articles Provided and Required Interface and UML Interface explain them.

  • Provided interfaces describe what the owner offers to its environment.
  • Required interfaces describe requests the owner may make to its environment through that port.

What happens to a request. A port can pass a received request on to an internal part. This is called delegation. The article Delegation Connector covers it.

Behavior port. A behavior port sends requests to the owner’s own behavior. If the owner has no behavior defined, anything arriving at that port is lost.

Lifecycle. When an instance of the owner is created, an instance of each of its ports is created too. Destroying a port also destroys the connectors attached to it.

Imagine an “Order Service” component with two ports. A port named “orders” offers an order-placing interface. A port named “payments” requires a payment interface. Callers see only these two named points on the border. The “orders” port hands each request to an internal part that handles it. When an Order Service instance is created, its two port instances are created with it.

A component with one port that provides an interface and one that requires an interface.

Diagram source
@startuml
component "Order Service" as OS {
portin "orders" as p1
portout "payments" as p2
}
interface "PlaceOrder" as I1
interface "Pay" as I2
I1 -- p1
p2 -( I2
@enduml
  • Ports that the environment can see are drawn straddling the boundary of their owner.
  • Each port shows which interfaces the owner provides and which it requires through that port.
  • Any behavior port belongs to an owner that has a defined behavior, so requests are not lost.
  • Ports that pass requests to internal parts are connected to those parts.