Marcello
Marcello

Reputation: 443

More than one relationship to a class in a Class Diagram

In a class diagram, is it possible to have two classes with more than one relationship? For example, a generalization relationship and a composition relationship?

For instance,

You can have either a composition relationship or a generalization relationship. A frozen Chocolate is a chocolate. But if you destroy the chocolate class the frozen chocolate class would also be destroyed. which also makes it a composition relationship.

But can you have both on the same diagram, or would you have to stick to one? Which one in this case?

Upvotes: 0

Views: 767

Answers (1)

ColinE
ColinE

Reputation: 70160

This is a generalization relationship, FrozenChocolate is a Chocolate but adds extra properties. It is not a compositions, you cannot say that Chocolate has a FrozenChocolate.

Your argument about destroying Chocolate resulting in FrozenChocolate also being destroyed is invalid. These are not object instances. You cannot say that destroying Animal means that Dog is destroyed.

Upvotes: 1

Related Questions