Module 23 Β· Design Patterns (All 23 GoF) β Lesson 9 of 23 Β· ~6 min
Decorator
Decorator: wrap an object to add behavior
Problem: you want to add responsibilities to a single object without subclassing or editing its class.
PawWalk scenario: a base walk price, then optional GPS and insurance surcharges. Wrap the price object; the wrapper's total adds its surcharge to the wrapped total.
Ruby's SimpleDelegator forwards everything to the wrapped object so you override only the method you're changing β but a plain wrapper class works just as well.