prototype_pattern

namespace prototype_pattern

Namespace for the Prototype pattern.

class ConcretePrototype1 : public prototype_pattern::Prototype
#include <prototype.hpp>

A concrete implementation of the Prototype interface.

ConcretePrototype1 represents a specific prototype with a string attribute.

Public Functions

explicit ConcretePrototype1(const std::string &attribute)

Constructor to initialize the attribute.

Parameters:

attribute – The value to initialize the prototype’s attribute.

virtual std::unique_ptr<Prototype> clone() const override

Creates a clone of the current object.

Creates a clone of the ConcretePrototype1 object.

This method is implemented by derived classes to return a copy of the current object.

Creates a new instance of ConcretePrototype1 by copying the current object’s attribute.

Performs a deep copy of the current object, creating an independent instance.

Returns:

A unique pointer to the cloned object.

Returns:

A unique pointer to the cloned ConcretePrototype1.

virtual void display() const override

Displays the details of the prototype.

Displays the details of the ConcretePrototype1.

This method is implemented by derived classes to provide a textual representation of the object.

Outputs the value of the attribute.

Outputs the value of the attribute to the standard output.

class ConcretePrototype2 : public prototype_pattern::Prototype
#include <prototype.hpp>

Another concrete implementation of the Prototype interface.

ConcretePrototype2 represents a specific prototype with an integer attribute.

Public Functions

explicit ConcretePrototype2(int attribute)

Constructor to initialize the attribute.

Parameters:

attribute – The value to initialize the prototype’s attribute.

virtual std::unique_ptr<Prototype> clone() const override

Creates a clone of the current object.

Creates a clone of the ConcretePrototype2 object.

This method is implemented by derived classes to return a copy of the current object.

Creates a new instance of ConcretePrototype2 by copying the current object’s attribute.

Performs a deep copy of the current object, creating an independent instance.

Returns:

A unique pointer to the cloned object.

Returns:

A unique pointer to the cloned ConcretePrototype2.

virtual void display() const override

Displays the details of the prototype.

Displays the details of the ConcretePrototype2.

This method is implemented by derived classes to provide a textual representation of the object.

Outputs the value of the attribute.

Outputs the value of the attribute to the standard output.

class Prototype
#include <prototype.hpp>

Abstract base class for the Prototype pattern.

The Prototype class defines an interface for cloning objects and displaying their details.

Subclassed by prototype_pattern::ConcretePrototype1, prototype_pattern::ConcretePrototype2

Public Functions

virtual ~Prototype() = default

Virtual destructor for proper cleanup in derived classes.

virtual std::unique_ptr<Prototype> clone() const = 0

Creates a clone of the current object.

This method is implemented by derived classes to return a copy of the current object.

Returns:

A unique pointer to the cloned object.

virtual void display() const = 0

Displays the details of the prototype.

This method is implemented by derived classes to provide a textual representation of the object.