Chain Of Responsibility Header

namespace chain_of_responsibility_pattern

Namespace for the Chain of Responsibility pattern.

class AbstractHandler : public chain_of_responsibility_pattern::Handler
#include <chain_of_responsibility.hpp>

Abstract base class that implements the chaining mechanism.

Subclassed by chain_of_responsibility_pattern::ConcreteHandlerA, chain_of_responsibility_pattern::ConcreteHandlerB

Public Functions

virtual ~AbstractHandler() = default
inline virtual Handler *setNext(std::shared_ptr<Handler> next) override

Sets the next handler in the chain.

Parameters:

next – The next handler.

Returns:

A reference to the current handler for chaining.

inline virtual void handleRequest(const std::string &request) const override

Forwards the request to the next handler if available.

Parameters:

request – The request to handle.

Protected Attributes

std::shared_ptr<Handler> nextHandler

The next handler in the chain.

class ConcreteHandlerA : public chain_of_responsibility_pattern::AbstractHandler
#include <chain_of_responsibility.hpp>

A concrete handler that processes specific requests.

Public Functions

inline virtual void handleRequest(const std::string &request) const override

Handles the request if applicable or forwards it to the next handler.

Parameters:

request – The request to handle.

class ConcreteHandlerB : public chain_of_responsibility_pattern::AbstractHandler
#include <chain_of_responsibility.hpp>

Another concrete handler that processes different requests.

Public Functions

inline virtual void handleRequest(const std::string &request) const override

Handles the request if applicable or forwards it to the next handler.

Parameters:

request – The request to handle.

class Handler
#include <chain_of_responsibility.hpp>

The interface for handling requests in the chain.

Subclassed by chain_of_responsibility_pattern::AbstractHandler

Public Functions

virtual ~Handler() = default
virtual void handleRequest(const std::string &request) const = 0

Handles the request or forwards it to the next handler.

Parameters:

request – The request to handle.

virtual Handler *setNext(std::shared_ptr<Handler> next) = 0

Sets the next handler in the chain.

Parameters:

next – The next handler.

Returns:

A reference to the current handler for chaining.

Inner Classes

Inner Namespaces