Mรณdulo 27 ยท Design Patterns (All 23 GoF) โ Lecciรณn 5 de 23 ยท ~6 min
Prototype
Make new objects by cloning an existing one
Prototype creates a new object by copying a fully-configured existing one, instead of building it from scratch. When a recurring booking template already has the walker, dog, and price set, cloning it and tweaking just the date is far cheaper than reassembling everything.
Python hands you this for free: copy.copy for a shallow copy, copy.deepcopy when nested objects must be copied too. No clone() method to write.