{"id":"6b08bd3c80884893657cc9dd","slug":"observer","title":"Observer: notify everyone without knowing anyone","summary":"The Observer pattern through a pierogi place's pantry: when the cheese runs out, the menu, the shopping list and alerts react on their own, and the pantry does not know they exist. Subscribing, unsubscribing, pitfalls and code in five languages.","servedLang":"en","availableLangs":["pl","en"],"topics":["observer","event-driven-architecture"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","behavioral","observer","events","pub-sub"],"level":"beginner","kind":"article","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":13,"stats":{"views":3,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:14:04.022Z","updatedAt":"2026-11-27T13:05:30.189Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"violet","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"The Observer design pattern in C#, TypeScript, Java, Go and Python: subscribing and unsubscribing, push vs pull, memory leaks, and how it differs from Pub/Sub.","wordCount":2467,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"In Halina's pierogi place the farmer's cheese always runs out at the worst moment. When the stock drops to zero, the potato-and-cheese pierogi have to disappear from the menu, cheese has to go onto the shopping list and – at weekends – Halina gets a text message. "},{"type":"text","text":"Observer","marks":[{"type":"bold"}]},{"type":"text","text":" lets the pantry announce a change and lets the interested parties react on their own, without knowing about each other."}]},{"type":"callout","attrs":{"variant":"tip","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The "},{"type":"text","text":"subject","marks":[{"type":"bold"}]},{"type":"text","text":" keeps a list of "},{"type":"text","text":"observers","marks":[{"type":"bold"}]},{"type":"text","text":" and notifies them when its state changes."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Observers "},{"type":"text","text":"subscribe and unsubscribe","marks":[{"type":"bold"}]},{"type":"text","text":" at runtime; the subject only knows their common interface."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A one-to-many relationship without rigid dependencies: a new receiver needs no changes in the subject."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"1 → N","label":"one subject, many receivers","hint":"the number of observers is not known up front"},{"value":"0","label":"receiver imports in the subject","hint":"the pantry does not know who is listening"},{"value":"3","label":"typical pitfalls","hint":"leaks, ordering and exceptions in observers"}]}},{"type":"heading","attrs":{"level":2,"id":"the-problem-a-pantry-that-knows-too-much"},"content":[{"type":"text","text":"The problem: a pantry that knows too much"}]},{"type":"paragraph","content":[{"type":"text","text":"The first version of the pantry called everyone interested directly:"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"pantry-before.ts"},"content":[{"type":"text","text":"class Pantry {\n  constructor(\n    private readonly menu: MenuBoard,\n    private readonly shopping: ShoppingList,\n    private readonly sms: SmsGateway,\n  ) {}\n\n  use(ingredient: string, amount: number): void {\n    const current = this.decrease(ingredient, amount);\n    if (current === 0) this.menu.hideDishesWith(ingredient);\n    if (current < 3) this.shopping.add(ingredient);\n    if (current < 3 && isWeekend()) this.sms.send('+48 600 000 000', `Low on ${ingredient}!`);\n    // next sprint: loyalty app, kitchen display, weekly report...\n  }\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"The "},{"type":"text","text":"Pantry","marks":[{"type":"code"}]},{"type":"text","text":" class depends on the menu, the shopping list and the SMS gateway. Every new receiver – a loyalty app, a kitchen display, a weekly report – means another constructor parameter and another "},{"type":"text","text":"if","marks":[{"type":"code"}]},{"type":"text","text":" in a method that was only supposed to decrease the stock. Unit tests of the pantry need fakes of three unrelated services, and an SMS gateway outage can break taking an ingredient off the stock."}]},{"type":"heading","attrs":{"level":2,"id":"the-solution-announce-the-change-do-not-call-the-recipients"},"content":[{"type":"text","text":"The solution: announce the change, do not call the recipients"}]},{"type":"paragraph","content":[{"type":"text","text":"The pantry stops calling concrete classes. Instead it offers a "},{"type":"text","text":"subscription","marks":[{"type":"bold"}]},{"type":"text","text":": anyone interested registers a function or an object with an "},{"type":"text","text":"onStockChanged","marks":[{"type":"code"}]},{"type":"text","text":" method. When the stock changes, the pantry walks the list and notifies everyone – without knowing whether the other side is the menu, an SMS or a unit test."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant K as Kitchen\n  participant P as Pantry (subject)\n  participant M as MenuBoard\n  participant S as ShoppingList\n  participant A as SmsAlert\n  M->>P: subscribe()\n  S->>P: subscribe()\n  A->>P: subscribe()\n  K->>P: use(\"cheese\", 4)\n  Note over P: cheese: 4 → 0\n  P->>M: onStockChanged(cheese, 4, 0)\n  P->>S: onStockChanged(cheese, 4, 0)\n  P->>A: onStockChanged(cheese, 4, 0)\n  M->>P: unsubscribe()","caption":"One state change, three receivers"}},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  direction LR\n  class Pantry {\n    -listeners: List~StockListener~\n    +subscribe(listener) Unsubscribe\n    +use(ingredient, amount)\n    +restock(ingredient, amount)\n  }\n  class StockListener {\n    <<interface>>\n    +onStockChanged(change)\n  }\n  Pantry o--> StockListener : notifies\n  StockListener <|.. MenuBoard\n  StockListener <|.. ShoppingList\n  StockListener <|.. SmsAlert","caption":"The structure of the Observer pattern"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Role"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In the example"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Responsibility"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Subject"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Pantry","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"keeps subscriptions and announces changes"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Observer"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"StockListener","marks":[{"type":"code"}]},{"type":"text","text":" / function type"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the common interface for reacting to a change"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Concrete observer"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"MenuBoard","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"ShoppingList","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"SmsAlert","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"does something with the notification, unaware of the others"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Event"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"StockChange","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"change data: ingredient, previous and current stock"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"implementation-in-five-languages"},"content":[{"type":"text","text":"Implementation in five languages"}]},{"type":"paragraph","content":[{"type":"text","text":"In C# the pattern is built into the language as "},{"type":"text","text":"event","marks":[{"type":"code"}]},{"type":"text","text":"; in TypeScript and Python a set of functions is enough; in Java it is a list of listeners; in Go a map of functions guarded by a mutex. In every variant subscribing returns a way to unsubscribe."}]},{"type":"codeGroup","attrs":{"title":"Observer – pantry stock"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"Pantry.cs"},"content":[{"type":"text","text":"var pantry = new Pantry();\nvar menu = new MenuBoard();\npantry.StockChanged += menu.OnStockChanged;\npantry.StockChanged += (_, e) =>\n{\n    if (e.Current < 3) Console.WriteLine($\"Shopping list: buy {e.Ingredient}\");\n};\n\npantry.Use(\"cheese\", 4);                    // menu hides dishes, shopping list reacts\npantry.StockChanged -= menu.OnStockChanged; // always unsubscribe long-lived subjects\npantry.Restock(\"cheese\", 10);\n\npublic sealed record StockChange(string Ingredient, int Previous, int Current);\n\npublic sealed class Pantry\n{\n    private readonly Dictionary<string, int> _stock = new() { [\"cheese\"] = 4, [\"potatoes\"] = 20 };\n\n    // The subject only knows the delegate type, not the subscribers.\n    public event EventHandler<StockChange>? StockChanged;\n\n    public void Use(string ingredient, int amount) => Set(ingredient, Stock(ingredient) - amount);\n    public void Restock(string ingredient, int amount) => Set(ingredient, Stock(ingredient) + amount);\n\n    private int Stock(string ingredient) => _stock.GetValueOrDefault(ingredient);\n\n    private void Set(string ingredient, int current)\n    {\n        var previous = Stock(ingredient);\n        if (previous == current) return;\n        _stock[ingredient] = current;\n        StockChanged?.Invoke(this, new StockChange(ingredient, previous, current));\n    }\n}\n\npublic sealed class MenuBoard\n{\n    public void OnStockChanged(object? sender, StockChange e)\n    {\n        if (e.Current == 0) Console.WriteLine($\"Menu: hiding dishes with {e.Ingredient}\");\n        else if (e.Previous == 0) Console.WriteLine($\"Menu: dishes with {e.Ingredient} are back\");\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"pantry.ts"},"content":[{"type":"text","text":"type StockChange = { ingredient: string; previous: number; current: number };\ntype Listener = (change: StockChange) => void;\n\nclass Pantry {\n  private readonly stock = new Map<string, number>([['cheese', 4], ['potatoes', 20]]);\n  private readonly listeners = new Set<Listener>();\n\n  /** Returns a function that unsubscribes the listener. */\n  subscribe(listener: Listener): () => void {\n    this.listeners.add(listener);\n    return () => this.listeners.delete(listener);\n  }\n\n  use(ingredient: string, amount: number): void {\n    this.set(ingredient, (this.stock.get(ingredient) ?? 0) - amount);\n  }\n\n  restock(ingredient: string, amount: number): void {\n    this.set(ingredient, (this.stock.get(ingredient) ?? 0) + amount);\n  }\n\n  private set(ingredient: string, current: number): void {\n    const previous = this.stock.get(ingredient) ?? 0;\n    if (previous === current) return;\n    this.stock.set(ingredient, current);\n    // Iterate over a copy, so a listener may unsubscribe while being notified.\n    for (const listener of [...this.listeners]) listener({ ingredient, previous, current });\n  }\n}\n\nconst pantry = new Pantry();\nconst stopMenu = pantry.subscribe(({ ingredient, previous, current }) => {\n  if (current === 0) console.log(`Menu: hiding dishes with ${ingredient}`);\n  else if (previous === 0) console.log(`Menu: dishes with ${ingredient} are back`);\n});\npantry.subscribe(({ ingredient, current }) => {\n  if (current < 3) console.log(`Shopping list: buy ${ingredient}`);\n});\n\npantry.use('cheese', 4); // menu hides dishes, shopping list reacts\nstopMenu();\npantry.restock('cheese', 10); // the menu no longer hears about it"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"Kitchen.java"},"content":[{"type":"text","text":"import java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.CopyOnWriteArrayList;\n\nrecord StockChange(String ingredient, int previous, int current) {}\n\n@FunctionalInterface\ninterface StockListener {\n    void onStockChanged(StockChange change);\n}\n\nclass Pantry {\n    private final Map<String, Integer> stock = new HashMap<>(Map.of(\"cheese\", 4, \"potatoes\", 20));\n    // Safe to iterate while listeners subscribe or unsubscribe.\n    private final List<StockListener> listeners = new CopyOnWriteArrayList<>();\n\n    /** Returns a handle that unsubscribes the listener when closed. */\n    AutoCloseable subscribe(StockListener listener) {\n        listeners.add(listener);\n        return () -> listeners.remove(listener);\n    }\n\n    void use(String ingredient, int amount) { set(ingredient, stock.getOrDefault(ingredient, 0) - amount); }\n\n    void restock(String ingredient, int amount) { set(ingredient, stock.getOrDefault(ingredient, 0) + amount); }\n\n    private void set(String ingredient, int current) {\n        int previous = stock.getOrDefault(ingredient, 0);\n        if (previous == current) return;\n        stock.put(ingredient, current);\n        var change = new StockChange(ingredient, previous, current);\n        listeners.forEach(l -> l.onStockChanged(change));\n    }\n}\n\npublic class Kitchen {\n    public static void main(String[] args) throws Exception {\n        var pantry = new Pantry();\n        var menu = pantry.subscribe(c -> {\n            if (c.current() == 0) System.out.println(\"Menu: hiding dishes with \" + c.ingredient());\n            else if (c.previous() == 0) System.out.println(\"Menu: dishes with \" + c.ingredient() + \" are back\");\n        });\n        pantry.subscribe(c -> {\n            if (c.current() < 3) System.out.println(\"Shopping list: buy \" + c.ingredient());\n        });\n        pantry.use(\"cheese\", 4);\n        menu.close(); // unsubscribe\n        pantry.restock(\"cheese\", 10);\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"pantry.go"},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n)\n\ntype StockChange struct {\n\tIngredient        string\n\tPrevious, Current int\n}\n\ntype Pantry struct {\n\tmu        sync.Mutex\n\tstock     map[string]int\n\tlisteners map[*func(StockChange)]struct{} // notification order is not guaranteed\n}\n\nfunc NewPantry() *Pantry {\n\treturn &Pantry{stock: map[string]int{\"cheese\": 4, \"potatoes\": 20}, listeners: map[*func(StockChange)]struct{}{}}\n}\n\n// Subscribe registers a listener and returns a function that removes it.\nfunc (p *Pantry) Subscribe(fn func(StockChange)) (unsubscribe func()) {\n\tkey := &fn // a unique key for this subscription\n\tp.mu.Lock()\n\tdefer p.mu.Unlock()\n\tp.listeners[key] = struct{}{}\n\treturn func() {\n\t\tp.mu.Lock()\n\t\tdefer p.mu.Unlock()\n\t\tdelete(p.listeners, key)\n\t}\n}\n\nfunc (p *Pantry) Use(ingredient string, amount int) { p.add(ingredient, -amount) }\n\nfunc (p *Pantry) Restock(ingredient string, amount int) { p.add(ingredient, amount) }\n\nfunc (p *Pantry) add(ingredient string, delta int) {\n\tp.mu.Lock()\n\tchange := StockChange{ingredient, p.stock[ingredient], p.stock[ingredient] + delta}\n\tp.stock[ingredient] = change.Current\n\tfns := make([]func(StockChange), 0, len(p.listeners))\n\tfor fn := range p.listeners {\n\t\tfns = append(fns, *fn)\n\t}\n\tp.mu.Unlock() // notify outside the lock, so listeners may call back into the pantry\n\tfor _, fn := range fns {\n\t\tfn(change)\n\t}\n}\n\nfunc main() {\n\tpantry := NewPantry()\n\tstopMenu := pantry.Subscribe(func(c StockChange) {\n\t\tif c.Current == 0 {\n\t\t\tfmt.Println(\"Menu: hiding dishes with\", c.Ingredient)\n\t\t}\n\t})\n\tpantry.Subscribe(func(c StockChange) {\n\t\tif c.Current < 3 {\n\t\t\tfmt.Println(\"Shopping list: buy\", c.Ingredient)\n\t\t}\n\t})\n\tpantry.Use(\"cheese\", 4)\n\tstopMenu()\n\tpantry.Restock(\"cheese\", 10)\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"pantry.py"},"content":[{"type":"text","text":"from dataclasses import dataclass\nfrom typing import Callable\n\n\n@dataclass(frozen=True)\nclass StockChange:\n    ingredient: str\n    previous: int\n    current: int\n\n\nListener = Callable[[StockChange], None]\n\n\nclass Pantry:\n    def __init__(self) -> None:\n        self._stock = {\"cheese\": 4, \"potatoes\": 20}\n        self._listeners: list[Listener] = []\n\n    def subscribe(self, listener: Listener) -> Callable[[], None]:\n        \"\"\"Registers a listener and returns a function that unsubscribes it.\"\"\"\n        self._listeners.append(listener)\n        return lambda: self._listeners.remove(listener)\n\n    def use(self, ingredient: str, amount: int) -> None:\n        self._set(ingredient, self._stock.get(ingredient, 0) - amount)\n\n    def restock(self, ingredient: str, amount: int) -> None:\n        self._set(ingredient, self._stock.get(ingredient, 0) + amount)\n\n    def _set(self, ingredient: str, current: int) -> None:\n        previous = self._stock.get(ingredient, 0)\n        if previous == current:\n            return\n        self._stock[ingredient] = current\n        change = StockChange(ingredient, previous, current)\n        for listener in list(self._listeners):  # copy: listeners may unsubscribe\n            listener(change)\n\n\ndef menu_board(change: StockChange) -> None:\n    if change.current == 0:\n        print(f\"Menu: hiding dishes with {change.ingredient}\")\n    elif change.previous == 0:\n        print(f\"Menu: dishes with {change.ingredient} are back\")\n\n\ndef shopping_list(change: StockChange) -> None:\n    if change.current < 3:\n        print(f\"Shopping list: buy {change.ingredient}\")\n\n\npantry = Pantry()\nstop_menu = pantry.subscribe(menu_board)\npantry.subscribe(shopping_list)\npantry.use(\"cheese\", 4)\nstop_menu()\npantry.restock(\"cheese\", 10)"}]}]}]},"toc":[{"id":"the-problem-a-pantry-that-knows-too-much","text":"The problem: a pantry that knows too much","level":2,"locked":false},{"id":"the-solution-announce-the-change-do-not-call-the-recipients","text":"The solution: announce the change, do not call the recipients","level":2,"locked":false},{"id":"implementation-in-five-languages","text":"Implementation in five languages","level":2,"locked":false},{"id":"push-or-pull","text":"Push or pull?","level":2,"locked":true},{"id":"pitfalls-the-diagrams-keep-quiet-about","text":"Pitfalls the diagrams keep quiet about","level":2,"locked":true},{"id":"a-short-history-of-observer","text":"A short history of Observer","level":2,"locked":true},{"id":"observer-vs-publish-subscribe","text":"Observer vs Publish/Subscribe","level":2,"locked":true},{"id":"when-to-use-it-and-when-not-to","text":"When to use it and when not to","level":2,"locked":true},{"id":"related-patterns","text":"Related patterns","level":2,"locked":true},{"id":"in-practice","text":"In practice","level":2,"locked":true},{"id":"test-yourself","text":"Test yourself","level":2,"locked":true},{"id":"exercise","text":"Exercise","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":42,"visibleBlocks":15,"resources":[{"id":"6b0857a53c96f2d34d0b321b","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=_BpmfnqjgzQ","embedUrl":"https://www.youtube-nocookie.com/embed/_BpmfnqjgzQ","title":"Observer Pattern – Design Patterns (ep 2)","description":"","author":"Christopher Okhravi","thumbnailUrl":"https://i.ytimg.com/vi/_BpmfnqjgzQ/hqdefault.jpg","durationSec":null,"lang":"en","topics":["observer"],"techs":["general"],"tags":[],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"seed","publishedAt":null,"popularity":0,"verifiedAt":"2026-11-26T00:00:00.000Z","curated":true,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:37.479Z","updatedAt":"2026-11-26T16:00:37.479Z"},{"id":"6b0857c23c96f2d34d0b4629","type":"article","provider":"web","url":"https://learn.microsoft.com/pl-pl/dotnet/standard/events/observer-design-pattern","embedUrl":null,"title":"Wzorzec projektowy obserwatora - .NET","description":"Dowiedz się więcej o wzorcu projektowania obserwatora na platformie .NET. Ten wzorzec umożliwia subskrybentowi rejestrowanie się i odbieranie powiadomień od dostawcy.","author":"Microsoft Learn","thumbnailUrl":"https://learn.microsoft.com/dotnet/media/dot-net-cross-platform.png","durationSec":null,"lang":"pl","topics":["observer"],"techs":["dotnet"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":50,"verifiedAt":"2026-11-26T11:26:51.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:04.995Z","updatedAt":"2026-11-26T16:01:04.995Z"},{"id":"6b0857bf3c96f2d34d0b4284","type":"article","provider":"web","url":"https://gameprogrammingpatterns.com/observer.html","embedUrl":null,"title":"Observer · Design Patterns Revisited · Game Programming Patterns","description":"","author":"Robert Nystrom","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["observer"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":65,"verifiedAt":"2026-11-26T11:26:36.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T23:13:50.362Z"},{"id":"6b0857b63c96f2d34d0b3ade","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/703-the-observer-pattern/id1253186678?i=1000638170776","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id1253186678?i=1000638170776","title":"703: The Observer Pattern","description":"In this episode of Syntax, Wes and Scott give a high level overview of the observer pattern, what is the observer, what are downsides to too many observers, and more. Show Notes 00:25 Welcome 01:42 Syntax Brought to you by Sentry 02:16 High level overview Syntax 694: What’s Up With Angular with…","author":"Syntax - Tasty Web Development Treats","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts221/v4/14/0a/50/140a50d8-f974-6542-e6d5-8362701cde23/mza_16091458091864441720.jpeg/600x600bb.jpg","durationSec":1162,"lang":"en","topics":["observer"],"techs":["typescript"],"tags":["podcast","performance","design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2023-12-11T11:00:00.000Z","popularity":76,"verifiedAt":"2026-11-26T10:57:52.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:53.924Z","updatedAt":"2026-11-26T16:00:53.924Z"},{"id":"6b0857c33c96f2d34d0b4666","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL16942701W","embedUrl":null,"title":"Head First design patterns","description":"","author":"Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates","thumbnailUrl":"https://covers.openlibrary.org/b/id/388950-L.jpg","durationSec":null,"lang":"en","topics":["factory-method","abstract-factory","builder","prototype","singleton","adapter","bridge","composite","decorator","facade","flyweight","proxy","chain-of-responsibility","command","iterator","mediator","memento","observer","state","strategy","template-method","visitor"],"techs":["java"],"tags":["book","design-patterns"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"2004-01-01T00:00:00.000Z","popularity":62,"verifiedAt":"2026-11-26T11:00:08.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:04.995Z","updatedAt":"2026-11-26T16:01:04.995Z"}],"challenges":[{"id":"6b0857af5a2625e44ecaad10","slug":"order-observer","title":"Order observer","summary":"An order notifies subscribers when its status changes; subscriptions can be cancelled and an audit log records transitions.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":null,"status":"published","difficulty":"medium","topics":["observer"],"techs":["dotnet","typescript"],"tags":["observer","events","behavioral"],"languages":["csharp","typescript"],"questionCount":null,"xp":20,"stats":{"attempts":1,"solves":1,"solutions":1,"comments":0},"solveRate":100,"publishedAt":"2026-11-26T16:00:47.864Z"},{"id":"6b093ddebd4755deb67ee06b","slug":"event-emitter","title":"Your own EventEmitter","summary":"Write a simplified version of Node.js `EventEmitter` – on, once, off, emit and the special `error` event. The Observer pattern in practice, with the traps of modifying the list during emission.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"algorithms","status":"published","difficulty":"easy","topics":["observer"],"techs":["typescript","javascript","python"],"tags":["design","events","observer","node","javascript"],"languages":["typescript","javascript","python"],"questionCount":null,"xp":10,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:54.007Z"},{"id":"6b093dc191bd8fbaf2a0c8d0","slug":"inventory-cqrs","title":"Inventory with CQRS – separate write and read models","summary":"Warehouse commands validated on their own write model, events on a bus and a projection building a read model with a low-stock report. The read model can be rebuilt from events alone.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"architecture","status":"published","difficulty":"medium","topics":["cqrs","event-driven-architecture"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["cqrs","read-model","projection","events","inventory"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":20,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:25.519Z"},{"id":"6b0857af5a2625e44ecaad13","slug":"design-patterns-basics-quiz","title":"Design patterns – basics","summary":"Six questions about classic GoF patterns: groups, intent and differences.","servedLang":"en","availableLangs":["pl","en"],"kind":"quiz","category":null,"status":"published","difficulty":"easy","topics":["builder","adapter","strategy","decorator","composite","facade","observer"],"techs":["general"],"tags":["quiz","gof","basics"],"languages":[],"questionCount":6,"xp":10,"stats":{"attempts":1,"solves":1,"solutions":0,"comments":0},"solveRate":100,"publishedAt":"2026-11-26T16:00:47.960Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"gof-behavioral","title":"GoF behavioral patterns","items":[{"slug":"strategy","title":"Strategy: interchangeable algorithms instead of an if-else ladder","current":false},{"slug":"observer","title":"Observer: notify everyone without knowing anyone","current":true},{"slug":"command","title":"Command: a request wrapped in an object","current":false},{"slug":"state","title":"State: an object that changes behaviour with its life stage","current":false},{"slug":"template-method","title":"Template Method: a fixed recipe, interchangeable ingredients","current":false},{"slug":"iterator","title":"Iterator: walking a collection without looking inside","current":false},{"slug":"chain-of-responsibility","title":"Chain of Responsibility: pass it on until someone takes care of it","current":false},{"slug":"mediator","title":"Mediator: components talk through a coordinator","current":false},{"slug":"memento","title":"Memento: a state snapshot without breaking encapsulation","current":false},{"slug":"visitor","title":"Visitor: new operations without changing classes","current":false}]}],"prev":{"slug":"strategy","title":"Strategy: interchangeable algorithms instead of an if-else ladder"},"next":{"slug":"command","title":"Command: a request wrapped in an object"},"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":104,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":90},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":61},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":59},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":46}]}}