Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+21 votes

What do the different types of diamond types mean for relationships in the UML diagrams and which side does the diamond go on? Is it the side that takes in the type, or the type itself? Like, for our zoo UML, does the diamond go on the Tourist class, or the Zoo class? Is the diamond supposed to be filled? Does that relationship even need a diamond or would a plain line be better?

asked in CSC305 Fall 2022 by (508 points)

2 Answers

+6 votes
Best answer

The diamond goes on the side that "has" the class on the other side. The white diamond (aggregation) indicates the diamond side is the "whole" and the arrow side is a "part." The black diamond (composition) is a specialization of aggregation, but indicates the part couldn't exist without the whole.

I've personally found that thinking of Car ◇→ Engine for aggregation, since the engine is a part of the car but can also exist on it's own, and thinking of Building ◆→ Room for composition, since the room wouldn't exist without the building.

I don't think the Tourist-to-Zoo relation needs a diamond, since it's only associated by use, not because it's a part of the Zoo itself. I think a line that's labeled something like "visits" would be fine.

I hope this helps!

answered by (8 points)
selected by

Also, you needn't worry about the distinction between the open and filled diamonds for this 305 course. The line between composition and aggregation is a bit subtle.

Noah is right that the Zoo -> Tourist arrow is a dependency, and not any sort if aggregation. The Zoo class uses the Tourist class, but an object of type Zoo does not contain or own Tourist objects (in the Java sense, which is what UML cares about). It doesn't matter whether zoos physically contain tourists in real life.

+4 votes

The UML reading pdfs in Moodle from Dale Skrien talk about the usage of those diamonds, and it's better explained there than I could do.

answered by (8 points)