Módulo 15 · Design Patterns in Go — Lección 2 de 8 · ~8 min
Strategy
Swap the algorithm, keep the caller
Strategy captures a family of interchangeable algorithms behind one contract so you can pick which runs at runtime. PawWalk prices a walk several ways — flat, weekend surge, member discount — and the code that charges the card shouldn't care which. It just applies the strategy it was handed.
In most languages Strategy means an interface plus a subclass per algorithm. Go gives you two idiomatic routes, and the lighter one is very Go: a function type. type PriceFunc func(int) int — any function with that shape is a pricing strategy. No interface, no struct.