composite_pattern
-
namespace composite_pattern
Namespace for the Composite pattern.
-
class Component
- #include <composite.hpp>
The Component interface declares common operations for both simple and complex objects.
Subclassed by composite_pattern::Composite, composite_pattern::Leaf
Public Functions
-
virtual void operation() const = 0
Performs the operation for the component.
Adds a child component (only meaningful for Composite).
Removes a child component (only meaningful for Composite).
-
inline virtual bool isComposite() const
Checks if the component is a composite.
- Returns:
True if composite, otherwise false.
-
virtual void operation() const = 0
-
class Composite : public composite_pattern::Component
- #include <composite.hpp>
The Composite class represents the complex components that may have children.
A Composite object can have both Leaf and other Composite objects as children.
Public Functions
Adds a child component to the composite.
- Parameters:
component – The child component to add.
Removes a child component from the composite.
- Parameters:
component – The child component to remove.
-
inline virtual bool isComposite() const override
Checks if the component is a composite.
- Returns:
True, as this is a Composite.
-
inline virtual void operation() const override
Performs the operation for the composite and delegates to child components.
-
class Leaf : public composite_pattern::Component
- #include <composite.hpp>
The Leaf class represents the end objects of a composition.
A Leaf cannot have any children. It implements the base Component interface.
-
class Component