Pattern choice pocket guide
Choose common GoF patterns based on the design pressure they solve.
Strategy vs State: what is the deciding difference? Compare Both use polymorphism; Strategy varies algorithm, State varies lifecycle behavior. Objection: 'Let's use Factory for everything we instantiate.' The code directly creates simple value objects and also creates payment gateway implementations. Your line Use a factory where creation is complex or the concrete type should vary. Direct construction is fine for simple value objects. A factory for every new adds ceremony without reducing coupling. Factory solves creation variation, not ordinary object creation. When does Observer fit? When one subject changes and an open-ended set of dependents should react without the subject…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in