decorator_pattern

namespace decorator_pattern

Namespace for the Decorator pattern.

class Component
#include <decorator.hpp>

The Component interface defines operations that can be altered by decorators.

Subclassed by decorator_pattern::ConcreteComponent, decorator_pattern::Decorator

Public Functions

virtual std::string getDescription() const = 0

Returns the description of the component.

Returns:

A string description.

virtual float cost() const = 0

Returns the cost of the component.

Returns:

A float representing the cost.

class ConcreteComponent : public decorator_pattern::Component
#include <decorator.hpp>

ConcreteComponent is a basic implementation of the Component interface.

Public Functions

inline virtual std::string getDescription() const override

Returns the description of the component.

Returns:

A string description.

inline virtual float cost() const override

Returns the cost of the component.

Returns:

A float representing the cost.

class ConcreteDecoratorA : public decorator_pattern::Decorator
#include <decorator.hpp>

A ConcreteDecorator that adds Feature A to the Component.

Public Functions

inline virtual std::string getDescription() const override

Delegates the getDescription method to the wrapped Component. Marked as pure virtual to enforce implementation in derived classes.

Returns:

A string description.

inline virtual float cost() const override

Delegates the cost method to the wrapped Component. Marked as pure virtual to enforce implementation in derived classes.

Returns:

A float representing the cost.

class ConcreteDecoratorB : public decorator_pattern::Decorator
#include <decorator.hpp>

A ConcreteDecorator that adds Feature B to the Component.

Public Functions

inline virtual std::string getDescription() const override

Delegates the getDescription method to the wrapped Component. Marked as pure virtual to enforce implementation in derived classes.

Returns:

A string description.

inline virtual float cost() const override

Delegates the cost method to the wrapped Component. Marked as pure virtual to enforce implementation in derived classes.

Returns:

A float representing the cost.

class Decorator : public decorator_pattern::Component
#include <decorator.hpp>

The Decorator class serves as the abstract base class for all decorators.

This class wraps a Component object and delegates the operations while allowing concrete decorators to extend or modify its behavior.

Subclassed by decorator_pattern::ConcreteDecoratorA, decorator_pattern::ConcreteDecoratorB

Public Functions

inline explicit Decorator(std::shared_ptr<Component> component)

Constructs the Decorator with a Component to wrap.

Parameters:

component – The Component to be decorated.

virtual std::string getDescription() const override = 0

Delegates the getDescription method to the wrapped Component. Marked as pure virtual to enforce implementation in derived classes.

Returns:

A string description.

virtual float cost() const override = 0

Delegates the cost method to the wrapped Component. Marked as pure virtual to enforce implementation in derived classes.

Returns:

A float representing the cost.