I am trying to figure out where should the diamond be placed in this example, I understand its a has-a relationship and diamond should be placed to indicate the whole and part relationship. I have created the UML so that the diamond is on the manufacturer side for both car and engine, like below
because it makes sense right? that the car and engine is being produced by the manufacturer, but the correct answer I was given in the class was to put the diamonds on car and engine respectively... it seems a bit odd to me since wouldn't the manufacturer be the "whole" in this relationship? Below is the spec:
I am trying to figure out where should I place the diamond sign
The diagram of the top is wrong, given the specifications:
The black diamond ("composite aggregation" in UML-speak or "composition" as shortcut) on the side of the engine would mean that Engine
owns Manufacturer
, and in particular if an engine is destroyed, so is the owned manufacturer. Same principle for the Car.
Moreover, according to the UML specifications, an instance of Manufacturer
can only belong to one composite at a time, either a n instance of Car
or Engine
, but not both at the same time. Which is a nonsense in real life, where a manufacturer can produce many car and many engines at the same time.
The black diamond MUST be on the side of the owner.
If the top diagram is what was taught in the classroom, the teacher has not understood UML very well, and you should consider a different guidance.
The diagram on the bottom is correct about the side of the diamond, but I'd recommend not to use composition at all. Here the comments to the second model:
*
instead of 0..*
. The latter is correct, but the former is nicer to read and is officially defined in the UML specifications to be strictly equivalent.