5

I have the problem mentioned in title of this post. By default, Composite Pattern has explicit implementation of Composite -> Component association. But I also need to implement association in reverse direction : Component -> Composite.

enter image description here

In short, what is the best solution for bidirectional association between Component and Composite object in Composite Pattern?

skaffman
  • 398,947
  • 96
  • 818
  • 769
slomir
  • 407
  • 2
  • 6
  • 16

1 Answers1

2

You only need an association between Component and itself, and call this "parent"

With this design, all leaf and composite will have a reference to his parent, this means Composite -> Component association

enter image description here

Pedre
  • 446
  • 1
  • 8
  • 16