Concrete Reusable Header

namespace object_pool_pattern

Namespace for the Object Pool pattern.

class ConcreteReusable : public object_pool_pattern::Reusable
#include <concrete_reusable.hpp>

Concrete implementation of the Reusable interface.

Represents an object that can be managed by an object pool. Each ConcreteReusable object has a unique identifier and maintains an internal state indicating whether it is currently in use.

This class provides functionality to “use” the object and reset it to its initial state when returned to the pool.

Public Functions

explicit ConcreteReusable(const std::string &id)

Constructs a reusable object with a unique identifier.

This identifier helps distinguish between different instances and is used in messages to indicate which object is being used or reset.

Parameters:

id – A unique identifier for the reusable object.

virtual void use() override

Simulates using the object.

Marks the object as in use and performs its functionality.

This method marks the object as “in use” and prints a message indicating the object is being used. If the object is already in use, it prints an error message to the console.

Overridden from the Reusable interface.

This method demonstrates how the object is used. If the object is already in use, a message is printed to indicate that it cannot be reused until it is reset.

  • If the object is not in use, it transitions to the “in use” state and prints a message to indicate it is being used.

  • If the object is already in use, an error message is printed.

virtual void reset() override

Resets the object to its initial state.

This method marks the object as “not in use” and clears any state associated with the previous usage. A message is printed to indicate that the object has been reset and is ready for reuse.

Overridden from the Reusable interface.

This method clears the “in use” state of the object, making it available for reuse in the object pool. A message is printed to indicate the object has been reset.

Private Members

std::string id

Unique identifier for the reusable object.

bool inUse = false

State indicating whether the object is in use.

Inner Classes

Inner Namespaces