The Observer Pattern: How the Hive Knows the Queen Moved
Placeholder prose. The queen does not write to every worker. She emits, and whoever cares reads it off the comb. The opening section sets up the analogy and states the pattern in one sentence.
Second paragraph of placeholder body copy. It names the coupling the pattern removes and the debugging cost it adds in return.
The phone tree
Placeholder lead-in to the code sample below.
hive/queen.ts
class Queen {
// the queen should not know these exist
constructor(
private nursery: Nursery,
private guards: GuardPost,
private logger: Logger,
) {}
move(cell: Cell) {
this.nursery.onQueenMoved(cell);
this.guards.onQueenMoved(cell);
this.logger.info("queen moved");
}
}A broadcast is cheap; knowing who is listening is what costs you.
Emit and forget
Closing placeholder paragraph. It restates the pattern, concedes where a direct call is simply clearer, and hands off to the next article.