Compose objects into tree structures to represent part-whole
hierarchies. Composite lets clients treat individual objects and
compositions of objects uniformly.
Declare the interface for objects in the composition.
Implement default behavior for the interface common to all classes,
Declare an interface for accessing and managing its child
Define an interface for accessing a component's parent in the
recursive structure, and implement it if that's appropriate
Define behavior for components having children.
Store child components.
Implement child-related operations in the Component interface.
self._children = set()
for child in self._children:
def add(self, component):
def remove(self, component):
Represent leaf objects in the composition. A leaf has no children.
Define behavior for primitive objects in the composition.
leaf = Leaf()
composite = Composite()
if __name__ == "__main__":