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:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Prototype')