Search code examples
design-patternsumlclass-diagramcomposite

What is the difference between a composite pattern expressed with arrow point to component and one without?


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!


Solution

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