Module 15 Β· Design Patterns in Go β Lesson 6 of 8 Β· ~6 min
Observer with channels
Notify subscribers when something happens
Observer lets a subject keep a list of interested parties and tell them all when its state changes β without knowing who they are. When a walk's status flips to in_progress, the owner's app, analytics, and the push service all need to hear it.
Go's concurrency toolkit gives this a native flavor: subscribers are channels. Subscribe appends a fresh channel to a slice and hands it back; Publish ranges over the slice and sends the event on each. Every subscriber receives on its own channel in its own goroutine β decoupled and concurrent by construction.