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.