Same diagram, different pattern: Strategy or State?
transcript
Two patterns draw exactly the same class diagram. Interviewers love asking which one is which. Most people guess.
A context holds an object behind an interface. It hands the work to that object. Several classes implement it. Strategy? Or State?
Strategy is chosen from outside. Then it never swaps itself. State switches itself. Every event can move it to a new state.
A vending machine. A coin goes in. Idle becomes has money. Pick a snack and it starts dispensing. Then it's idle again. Nobody outside chose those moves. The machine did. That's State.
Now a parking lot. Its pricing rule is handed in once, when the lot is built. The lot just asks it for a fee. It never asks which tariff it holds. Car after car, it never changes itself. That's Strategy.
So ask one question. Who changes the behaviour, and when? Changed from outside? Strategy. Changes itself? State.
Full breakdown in the lecture.