odiseh
odiseh

Reputation: 26517

UML notation: What is this relationship?

Looking at below UML diagram (decorator pattern), what is the name of relationship between Decorator and component? Is it Association?

Decorator pattern

Upvotes: 1

Views: 454

Answers (6)

UML GURU
UML GURU

Reputation: 1462

You are describing an aggregation. The problem is that this diagram should be reversed from your code or you should get a code from your diagram. Just graphical UML designs are not enough for me.

When I use tools with no code mapping to UML then my modeling is sooner or later horrible !! I create nice diagrams but except for presentation nobody really use them. I have realized that it was a waste of time for everybody in the team. I have switched to a professional tool then my project was really used by the team and not only a graphical view used once during a story board. What surprised me is developers have also corrected my diagrams because at implementation stage what was good in UML was impossible in the code :-) This is why UML as standalone has no value for me if you use the class diagram. I did this mistake using open source graphical tool but will not do it again !!

Upvotes: 0

Raveline
Raveline

Reputation: 2678

Aggregation. Easiest way to see the difference is with "to be" and "to have". An object Component "has a decorator". An object Decorator "is a component".

Upvotes: 0

sfinnie
sfinnie

Reputation: 9952

The two relationships between Component and Decorator constitute another pattern - Composite.

  • Decorator is a subtype of Component (rel with triangle)
  • Decorator aggregates (includes) many Components (rel with diamond)

It allows recursive tree structures to be created. Operations called on the aggregate Decorator are delegated to its contained elements. Hence, in your diagram, the behaviour of Decorator.Operation() is to call Component.Operation() on each of its aggregated Components. Since one or more of thpse could themselves be a Decorator, the call to Operation() propagates through the tree structure.

Upvotes: 3

Mario The Spoon
Mario The Spoon

Reputation: 4859

One is an extension the other one aggregation (that's the one with the small nob at Decorator). Meaning that a Decorator can contain 0 or more Components.

hth

Mario

Upvotes: 2

amra
amra

Reputation: 16875

It's aggregation. Decorator has many Components.

Upvotes: 1

Lie Ryan
Lie Ryan

Reputation: 64847

extends relationship

Upvotes: -2

Related Questions