Closed Cotel closed 7 years ago
I was confused with this pattern because I found 2 examples that were doing different things.
This is one. In here, they use the pattern to treat a group of objects as one and operate with them as a group.
This is the other one. In here, they use the pattern to establish a hierarchy in one object. This time, it is only for representing data, it hasn't any behaviour. I think this example doesn't need a pattern, this could be easily done with a Tree data structure.
It is confusing because they are alike but they do not do the same things. What is the real purpose of this pattern?
I don't like first example because are broken liskov principle. In Hoja
class. The english versiΓ³n has better implementation, because Leaf
doesn't not have add
function π
I don't understand the second example, because composite is about more than 1 object -\(00)/-
To be honest I didn't know how to test this at all because I think I am not using the pattern correctly. Even the Composite in Chain of Responsability is better π€
I will think
@Cotel You can see how it's does that you wanted to do π
How it's done*.
Reviewing now π
This close #18
Don't mind the commit name, I forgot to change it π
The composite pattern is useful to represent a group of objects as one. Don't know if this example is enough but I couln't think of a more complex example where this can be useful.
It would be great if somebody told if there are examples of everyday code where we are using this pattern (for example, every DAO is a Facade. I would like to see something like that for Composite)