Polski

Learning path · 10 · intermediate

GoF behavioral patterns

Ten behavioral patterns from the Gang of Four catalog, told through Halina's pierogi place moving online: from Strategy and Observer to Memento and Visitor. Every article has a diagram, code in C#, TypeScript, Java, Go and Python, a quiz and advice on when not to use the pattern.

  1. Strategy: interchangeable algorithms instead of an if-else ladder

    The Strategy pattern through courier assignment in a pierogi place: a family of interchangeable algorithms behind one interface, swapped at runtime. Code in C#, TypeScript, Java, Go and Python.

  2. Observer: notify everyone without knowing anyone

    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…

  3. Command: a request wrapped in an object

    The Command pattern through a waiter's terminal in a pierogi place: every action on the ticket is an object with execute and undo, so it can be undone, redone, kept in a history and sent to a queue. Code in five languages.

  4. State: an object that changes behaviour with its life stage

    The State pattern through an order in a pierogi place: New, Paid, InKitchen, Delivered and Cancelled as separate objects that guard the allowed transitions themselves. A state machine without an if-else ladder, code in five languages.

  5. Template Method: a fixed recipe, interchangeable ingredients

    The Template Method pattern through importing supplier price lists: the base class fixes the order of steps, and subclasses provide parsing and optional hooks. The Hollywood principle, an inheritance-free variant in Go and code in five…

  6. Iterator: walking a collection without looking inside

    The Iterator pattern through orders from a delivery app fetched page by page: the loop in the report knows nothing about pagination, and pages load lazily, only when needed. Generators, yield and iter.Seq in five languages.

  7. Chain of Responsibility: pass it on until someone takes care of it

    The Chain of Responsibility pattern through complaints in a pierogi place: a bot, a shift manager and the owner form a chain, and a complaint travels until it reaches someone authorised. The classic variant and the middleware pipeline,…

  8. Mediator: components talk through a coordinator

    The Mediator pattern through the order form of a pierogi place: the delivery choice, address, time slot and button do not know each other, and the rules of their cooperation live in one place. Plus an honest look at MediatR and code in…

  9. Memento: a state snapshot without breaking encapsulation

    The Memento pattern through a menu editor: Halina saves versions of the menu and returns to them with one click, while the history keeps snapshots without seeing what is inside. Copies instead of references, memory costs and code in five…

  10. Visitor: new operations without changing classes

    The Visitor pattern through a menu: dishes, drinks and sets stay untouched, while pricing, an allergen report or an export are separate visitor objects. Double dispatch, a comparison with pattern matching and code in five languages.

Learning paths