Wikipedia says:

individual objects

It seems to me that the example in the same Java wikipedia does not correspond to this statement. Print method:

public void print() { for (Graphic graphic : childGraphics) { graphic.print(); } } 

But in C # everything is in order:

 public override void Display(int depth) { Console.WriteLine(new String('-', depth) + name); // Recursively display child nodes foreach (Component component in children) { component.Display(depth + 2); } } 

What I see? In Java, the composite works out all its children and forgets about itself!

In C #, the action itself is inherent in itself, and then the children are trained, which is correct in my understanding.

I did not understand something in the template or is it really a mistake?

Link to material: Linker (design pattern)

    2 answers 2

    OOP patterns manipulate interfaces β€” not implementation. Therefore, the phrase "full node" should be considered in the sense that any external code can work with the composite without knowing that it is a composite.

    Therefore, the implementation of the print / Display method is completely unimportant. What is important is the fact that this method exists, it works and can be called on the composite in the same way as any other node.

      As far as I understand, it all depends on the logic of what the code should do. If it has to print some values ​​in the nodes, and if the composite node does not contain this value (java example), then naturally, it is recursively trying to get to those that contain. In Sharp, all nodes with depth are baked, hence the execution of third-party code in the composite node. I hope I did not confuse you =)

      And the client in both cases does not know anything, he simply calls the print method, and what is done inside, he is not aware