Prototype API Documentation

Prototype Pattern Implementation in Python.

This module provides an implementation of the Prototype Pattern, enabling object creation by cloning existing instances instead of instantiating new ones.

class Prototype[source]

Bases: ABC

Abstract base class for prototypes.

Defines the interface for cloning and displaying objects.

abstractmethod clone()[source]

Create a clone of the current object.

Returns:

A new instance that is a copy of the current object.

abstractmethod display()[source]

Display the details of the object.

This method should be implemented by concrete prototypes to output their attributes.

class ConcretePrototype1(attribute)[source]

Bases: Prototype

A concrete implementation of the Prototype interface with a string attribute.

Parameters:

attribute (str)

__init__(attribute)[source]

Initialize the prototype with a string attribute.

Parameters:

attribute (str) – A string representing the object’s attribute.

clone()[source]

Create a shallow clone of the current object.

Returns:

A new instance of ConcretePrototype1 with the same attribute.

display()[source]

Display the attribute of the object.

class ConcretePrototype2(attribute)[source]

Bases: Prototype

A concrete implementation of the Prototype interface with an integer attribute.

Parameters:

attribute (int)

__init__(attribute)[source]

Initialize the prototype with an integer attribute.

Parameters:

attribute (int) – An integer representing the object’s attribute.

clone()[source]

Create a shallow clone of the current object.

Returns:

A new instance of ConcretePrototype2 with the same attribute.

display()[source]

Display the attribute of the object.