Module 23 Β· Design Patterns (All 23 GoF) β Lesson 5 of 23 Β· ~6 min
Prototype
Prototype: create new objects by cloning an existing one
Problem: building a fresh object from scratch is expensive or fiddly, but you already have a good example to copy.
PawWalk scenario: a recurring-booking template. Duplicate it, change the date on the copy, and the original template stays untouched for next week.
Ruby gives you this for free: dup (shallow copy, ignores frozen/singleton state) and clone (also copies frozen state). No Prototype interface required.