Problem Statement
Creating new objects by initializing them from scratch can be slow and error-prone, especially when many objects share similar properties. This leads to duplicated code and inconsistent object states when copying manually.
This diagram shows the client requesting a clone from the prototype object, which returns a new cloned object.
### Before Prototype Pattern (manual copy) class Car: def __init__(self, model, color, options): self.model = model self.color = color self.options = options car1 = Car('Sedan', 'Red', ['GPS', 'Sunroof']) # Manual copy car2 = Car(car1.model, car1.color, list(car1.options)) ### After Prototype Pattern (using clone method) import copy class CarPrototype: def __init__(self, model, color, options): self.model = model self.color = color self.options = options def clone(self): return copy.deepcopy(self) car1 = CarPrototype('Sedan', 'Red', ['GPS', 'Sunroof']) car2 = car1.clone()