LearningTech

Creational

Prototype

Description

Creates new objects by copying an existing object, known as the prototype.

Where to use

  • When object creation is expensive.
  • \n
  • Cloning complex states.

Real World Example

In a game, spawning 1000 'Goblin' enemies. Instead of running the initialization code 1000 times, you create one Goblin and clone it 999 times.

Code Example

class Prototype:
    def __init__(self):
        pass

    def execute(self):
        print('Executing Prototype')