CloudCoders / Design-Patterns

Project for learning and discuss about design patterns
16 stars 1 forks source link

Added Composite Pattern #23

Closed Cotel closed 7 years ago

Cotel commented 7 years ago

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)

Cotel commented 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?

tonilopezmr commented 7 years ago

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)/-

Cotel commented 7 years ago

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 πŸ€”

tonilopezmr commented 7 years ago

I will think

tonilopezmr commented 7 years ago

@Cotel You can see how it's does that you wanted to do πŸ‘

Cotel commented 7 years ago

How it's done*.

Reviewing now πŸ‘