0

I am designing a program and I would like to make use of the composite pattern. I have noticed that there are two ways of expressing it: Class diagram of composite pattern with no arrow pointing to the component class

and

Class diagram of composite pattern with arrow pointing to the component class

What is the difference between the two? Thank you!

elena
  • 889
  • 2
  • 11
  • 19
  • Possible duplicate of [UML Aggregation with and without arrow head](https://stackoverflow.com/questions/21738757/uml-aggregation-with-and-without-arrow-head) – jaco0646 Jun 07 '18 at 14:02

2 Answers2

3

There is no difference except that the one with the zero accepts composite objects that are empty and the other one guarantees that a composite object has at least one part.

Alper
  • 3,424
  • 4
  • 39
  • 45
  • thank you for your reply! So the presence of the arrow does not change anything? – elena Jun 03 '18 at 13:28
  • No, I'd say the arrow is superfluous (especially a thin one). – Alper Jun 04 '18 at 09:33
  • 1
    The arrow is not superfluous. It indicates in which direction you can expect to be able to navigate easily. Missing arrows indicate that the navigability is unspecified. – Geert Bellekens Jun 04 '18 at 18:33
3

As @alper already states there is no real difference between both notations.

The top one allows navigation in both directions (so Component can see Composite namely as parent) while the lower one does not have this navigability. To make make the missing parent relation more obvious the author has added the arrow.

So the top one is a more universal implementation of the Composite pattern.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86