Module 27 ยท Design Patterns (All 23 GoF) โ Lesson 21 of 23 ยท ~6 min
Strategy
Swap interchangeable algorithms at runtime
Strategy captures a family of algorithms behind one interface so you can pick which to use at runtime. Pricing has several strategies โ flat, surge, member-discount โ and the right one depends on the booking. The calculator doesn't care which; it just applies the strategy it's given.
Say it plainly: in Python a strategy is almost always just a callable โ a function or lambda you pass in. No Strategy base class, no subclass per algorithm.