Mediator or Observer? Ask which way it talks
transcript
Two patterns let objects react without calling each other. Interviewers love asking which is which.
A weather service gets a new reading and sends it to a thousand apps. The apps never talk to each other. Which pattern?
Observer is a one way broadcast. One subject, many listeners, no rules between them. The weather service is Observer. A mediator is two way. Many parts report to one room. The room holds the rules that connect them.
In a group order, locking the cart changes what other parts may do. The roster, the pay desk, the banner. The rules between those parts live in the room. That's Mediator.
They often work together. The parts publish events, and the room subscribes to them. Then the room applies the rules. Observer is the wire. Mediator is the brain.
So ask one question. Is it a one way broadcast, or a room that holds the rules? Broadcast, Observer. Rules between the parts, Mediator.
Full breakdown in the lecture.