Strategy Header

namespace strategy_pattern

Namespace for the Strategy pattern.

class ConcreteStrategyA : public strategy_pattern::Strategy
#include <strategy.hpp>

Concrete Strategy A implements a specific algorithm.

Public Functions

inline virtual void execute() const override

Executes the algorithm encapsulated by the strategy.

class ConcreteStrategyB : public strategy_pattern::Strategy
#include <strategy.hpp>

Concrete Strategy B implements a specific algorithm.

Public Functions

inline virtual void execute() const override

Executes the algorithm encapsulated by the strategy.

class Context
#include <strategy.hpp>

Context maintains a reference to a Strategy object and delegates behavior to it.

Public Functions

inline void setStrategy(std::unique_ptr<Strategy> strategy)

Sets the strategy for the context.

Parameters:

strategy – A unique pointer to the strategy to use.

inline void executeStrategy() const

Executes the strategy.

Private Members

std::unique_ptr<Strategy> strategy

Pointer to the current strategy.

class Strategy
#include <strategy.hpp>

The Strategy interface defines a common interface for all supported algorithms.

Subclassed by strategy_pattern::ConcreteStrategyA, strategy_pattern::ConcreteStrategyB

Public Functions

virtual ~Strategy() = default
virtual void execute() const = 0

Executes the algorithm encapsulated by the strategy.

Inner Classes

Inner Namespaces