object_adapter_pattern

namespace object_adapter_pattern

Namespace for the Object Adapter pattern.

class Adaptee
#include <object_adapter.hpp>

The Adaptee class provides existing functionality needing adaptation.

The Adaptee defines methods that are incompatible with the Target interface but offer useful functionality. The Adapter class bridges the gap between the Adaptee and the Target interface, enabling seamless integration.

Public Functions

inline void specificRequest() const

A specific method offered by the Adaptee.

This method demonstrates functionality that needs adaptation to match the Target interface.

class Adapter : public object_adapter_pattern::Target
#include <object_adapter.hpp>

The Adapter class adapts the Adaptee to the Target interface.

The Adapter uses composition to hold an instance of Adaptee and translates calls from the Target interface into calls to the Adaptee’s methods. This enables the client to interact with Adaptee functionality seamlessly.

Public Functions

inline explicit Adapter(Adaptee *adaptee)

Constructs an Adapter with a given Adaptee instance.

The Adapter holds a reference to the Adaptee, enabling it to translate client calls into the Adaptee’s specific methods.

Parameters:

adaptee – Pointer to the Adaptee instance to be adapted.

inline virtual void request() const override

Implements the Target interface by delegating to the Adaptee.

This method adapts the Target’s request() call into a call to the Adaptee’s specificRequest() method.

class Target
#include <object_adapter.hpp>

The Target interface defines the expected interface for the client.

The Target interface acts as a standard contract for clients that interact with the system. By abstracting specific implementation details, this interface promotes flexibility and decoupling between the client and concrete implementations.

Subclassed by object_adapter_pattern::Adapter

Public Functions

virtual ~Target() = default

Virtual destructor ensures proper cleanup of derived objects.

virtual void request() const = 0

Standard method expected by the client.

Derived classes implement this method to provide behavior tailored to the client’s expectations.