Skip to content

Files

Latest commit

 

History

History
49 lines (33 loc) · 1.22 KB

CompositePattern.md

File metadata and controls

49 lines (33 loc) · 1.22 KB

The Composite Pattern

C++ Project Example

Link:

Theory

The Composite pattern allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

Composite pattern provides a mechanism for treating groups of objects the same as an individual object (this is often known as part-whole hierarchy).

The Composite pattern allows us to build structures of objects in the form of trees that contain both compositions of objects and individual objects as nodes.

Using a composite structure, we can apply the same operations over both composites and individual objects. In other words, in most cases we can ignore the difference between composition of objects and individual objects.

Class Diagram

Loading
classDiagram
direction LR

class Client

class Component {
    +operation()
    +add(Component)
    +remove(Component)
    +getChild(int)
}

class Composite {
    +operation()
    +add(Component)
    +remove(Component)
    +getChild(int)
}

class Leaf {
    +operation()
}

Client --> Component

Component  <|-- Composite

Component  <-- Composite

Component  <|-- Leaf