I’m focusing on trying to understand UML diagrams and learning to interpret them in order to implement the designs they describe. In the following diagram, I am not clear on what the implementation for Port Operation
should be.
It looks like it should be a class/entity the same as the others in the diagram. I understand the relationship between Leg and Port Operation
is bidirectional. But it seems that it does not make sense to have a class just for port operations, and having Load() and Unload() methods in Leg doesn’t make much sense since a Leg class does not represent a port or its’ operations.
When reading UML diagrams, is it expected that there are multiple ways for someone to implement it? i.e some ways are better than others, and it’s a judgement call as to how someone implements it?
What would be the recommened implementation for the above diagram with regards to Port Operation?
UML is a drawing/design language, but it does not specify how the drawing elements are mapped to the constructs of your programming language. In that way, UML provides for multiple ways to implement things.
Also, an UML diagram usually does not show everything, because that would clutter the diagram too much, so only the relevant details are shown in each diagram.
With the above in mind, you should regard each UML diagram as a definitive design document for the portion of the application that is shown therein. Presumably someone has put thought into the diagram and can give a reason for the existence of each of the classes and interconnections.
When implementing the design from an UML diagram, you should strive that other programmers, who know the design, can recognize the design in your code.
In the design in question, Port Operation
and Leg
are two distinct classes. Between these classes, there are two bi-directional links. As I read it, a Leg
instance knows about two, different, Port Operation
instances, one for loading and the other for unloading. The names next to the lines/arrows are not method names, but they clarify the context of the connection. In the implementation they are typically used as basis for the attribute name of the reference that signifies the connection.