Design Patterns Series 14 - Composite Pattern
This post will be about the second pattern in the alliance. In the last post we explored first pattern in this alliance, the Iterator Pattern , and today is the time of Composite Pattern . The Composite Pattern : The Composite Pattern is all about creating tree-like structures where the leaves in the structure can be treated in the same way as the branches(which are substructures that can contain multiple leaves, as well as other branches). The idea here is that, to make life easier, you should be able to treat the leaves and compositions of leaves in a tree structure the same. You use the Composite pattern to " Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformally ". That is typical of Composite Pattern - when you ask a branch to perform some action, it iterates over all its contained leaves and branches. The insight behind The Composite Pattern is r...