0

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?

5
  • 1
    I don't see a composition relationship. Can you declare a FrozenChocolate frochoc; in the Chocolate class? Commented Nov 24, 2012 at 10:21
  • You mean create an object FrozenChocolate? Commented Nov 24, 2012 at 10:24
  • If you had to have a frozen Chocolate class. Why wouldn't it not be a composition relationship with the chocolate class? Commented Nov 24, 2012 at 10:25
  • That's what composition means. Every instance of Chocolate will have its own FrozenChocolate object, which doesn't seem reasonable. Commented Nov 24, 2012 at 10:26
  • If thats what it means then why dont you see a composition relationship? Commented Nov 24, 2012 at 10:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.