In a UML Composite Structure Diagram: What is a "port"? And how would I implement one in, say Java?
A composite structure diagram is a diagram that shows the internal structure of a classifier, including its interaction points to other parts of the system. It shows the configuration and relationship of parts, that together, perform the behavior of the containing classifier.
In UML modeling, interfaces are model elements that define sets of operations that other model elements, such as classes, or components must implement. An implementing model element realizes an interface by overriding each of the operations that the interface declares.
The current UML standards call for 13 different types of diagrams: class, activity, object, use case, sequence, package, state, component, communication, composite structure, interaction overview, timing, and deployment.
As UML diagrams, both composite structure diagrams and class diagrams are used to visualize and organize the actors, interactions, and artifacts within a system.
I would put forward that, in an OO language like Java, the port concept utilised by composite structure diagrams is (usually) actually implemented as the calling of a method of a member object by the containing object after a call is made on a method of the containing object.
This is a bit like the Facade or Delegation patterns, except that the containing object actually must "own" the member object.
See the Delegation WikiPedia article for sample implementations in a number of languages.
To answer the first part of the question, from the UML User Manual (2nd Edition) (admittedly in relation to components):
A port is an explicit window into an encapsulated component. In an encapsulated component, all of the interactions into and out of the component pass through ports. The externally visible behavior of the component is the sum of its ports, no more and no less. In addition, a port has identity.
...and from UML distilled (3rd Edition):
Ports allow you to group the required and provided interfaces into logical interactions that a component has with the outside world.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With