Structural

Composite

Description

Lets you compose objects into tree structures and then work with these structures as if they were individual objects.

Where to use

  • File systems.
  • \n
  • GUI element trees.

Real World Example

A 'Folder' contains 'Files' and other 'Folders'. You can call 'getSize()' on a Folder, and it recursively calculates the size of everything inside.

Code Example

class Composite:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Composite')