tags:

views:

77

answers:

6

hi

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

Decorator pattern

BTW, why the uploaded image is not shown?

A: 

extends relationship

Lie Ryan
AFAIK, extends relationship is between usecases not classs.
odiseh
@odiseh: you are wrong. There are extends relationship between classes.
Lie Ryan
+1 Lie Ryan - extends is valid between classes.
sfinnie
+1  A: 

It's aggregation. Decorator has many Components.

amra
+2  A: 

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

Mario The Spoon
+1 I missed the aggregation arrow on the right side.
Lie Ryan
+3  A: 

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.

sfinnie
Very Well spotted!
Chris McCauley
A: 

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".

Raveline
A: 

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 !!