Proxy Header

namespace proxy_pattern

Namespace for the Proxy pattern.

class Proxy : public proxy_pattern::Subject
#include <proxy.hpp>

The Proxy controls access to the RealSubject.

The Proxy adds additional functionality such as authentication or lazy initialization.

Public Functions

inline explicit Proxy(bool isAuthenticated)

Constructor initializes the Proxy with authentication status.

Parameters:

isAuthenticated – Whether the client is authenticated.

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

Handles the request by checking authentication and delegating to RealSubject.

Parameters:

resource – The resource being requested.

Private Members

std::unique_ptr<RealSubject> realSubject

The RealSubject instance, initialized lazily.

bool isAuthenticated

Indicates if the user is authenticated.

class RealSubject : public proxy_pattern::Subject
#include <proxy.hpp>

The RealSubject performs the actual work of handling requests.

Public Functions

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

Handles the request and simulates actual processing.

Parameters:

resource – The resource being accessed.

class Subject
#include <proxy.hpp>

The Subject interface defines the common operations for the Proxy and RealSubject.

Subclassed by proxy_pattern::Proxy, proxy_pattern::RealSubject

Public Functions

virtual ~Subject() = default
virtual void request(const std::string &resource) const = 0

Handles the request in a format expected by the client.

Inner Classes

Inner Namespaces