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:
and
What is the difference between the two? Thank you!
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:
and
What is the difference between the two? Thank you!
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.
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.