Ryman Holmes
Ryman Holmes

Reputation: 756

Trouble with Composition and Aggregation relationships UML

I am having some troubles with Composition and Aggregation relationships in UML, I do understand the whole/part relationship so if a class cannot exist without its whole then it makes it a strong composition relationship and if it still can exist without its whole then it makes it a weak aggregation relationship.

However sometimes it gets a little more tricky than that when dealing with real software requirements. I have a class diagram below with all necessary, attributes, operations and properties included which are all correctly shown in UML standards however I am unsure about my relationships:

1 Interface and 6 classes

Could someone confirm if my relationships are correct or not?

Many Thanks

UML Diagram

Upvotes: 1

Views: 3245

Answers (2)

Gangnus
Gangnus

Reputation: 24464

It is vice versa. The black rhombus should be at the side, that holds or simply is the set of the objects from the other side of connection.

Also an occupant can exist without location (an explorer before the adventure), so it is rather aggregation dependency, not composition. As for maze, the maze IS a composition of locations, OK. Explorer to stone dependency is again aggregation - stone can be without Explorer easily.

Also, I am not sure that stone should descend directly from Occupant. I'd define CaveObject class (because Object is already busy) and derive Stone and Occupant from it, and Snake and Explorer from the last. And I'd add an interface TemporaryOccupant, and make Explorer to implement it. In that interface I'll put functions to move from one location to another.

As for Species/Snakes, I am afraid, I am at lost - what belongs to what? Rather, species should be another interface and both the snake and the Explorer should implement it, too.

BTW, I see here another error: You connect Snake and Species - it IS an attribute of other class with the type of another class already. Don't declare it as one more parameter in the class rectangle.

Your Explorer has only getter for Name, but no Setter. Your drop() has no parameter to set what will be dropped.

Upvotes: 0

Bruce
Bruce

Reputation: 2310

There are a few issues. The best example of composition is Maze to Location. Your connector has the diamond on the wrong end. The class that consists of the other class has the diamond, so Maze consists of Locations. Maze should have the diamond. The Species - Snake relationship is suspect since there are many species besides snakes and species don't consist of snakes. I also don't think that Explorer consists of Stones. The explorer-stone relationship is a straight (if I understand your application) 1 to many relationship. I would also add multiplicity to the diagram to clarify 1:1, 1:many, etc. Please correct your diagram and repost.

Upvotes: 1

Related Questions