{"id":"6b08bd3080884893657cc910","slug":"command","title":"Command: a request wrapped in an object","summary":"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.","servedLang":"en","availableLangs":["pl","en"],"topics":["command","cqrs"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","behavioral","command","undo-redo","queue"],"level":"intermediate","kind":"article","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":12,"stats":{"views":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:52.954Z","updatedAt":"2026-11-27T13:04:26.147Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"violet","background":"hex","weaveResources":true,"toc":"right"},"seoDescription":"The Command design pattern in C#, TypeScript, Java, Go and Python: undo and redo, job queues, macros, and how it differs from commands in CQRS.","wordCount":2354,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"A waitress in Halina's pierogi place adds two portions of potato-and-cheese pierogi, a compote and a discount for a regular to the ticket. The customer changes their mind – the compote has to go, but the pierogi stay. "},{"type":"text","text":"Command","marks":[{"type":"bold"}]},{"type":"text","text":" turns every click into an object that knows how to execute itself and how to undo itself. Undo, history and the kitchen queue stop being separate problems."}]},{"type":"callout","attrs":{"variant":"tip","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A command "},{"type":"text","text":"wraps a request in an object","marks":[{"type":"bold"}]},{"type":"text","text":": who should do something (the receiver), what, and with which parameters."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The invoker runs commands without knowing what is inside – it only knows "},{"type":"text","text":"execute()","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Since a request is an object, it can be "},{"type":"text","text":"stored","marks":[{"type":"bold"}]},{"type":"text","text":": in a history (undo), in a queue (later), in a log (audit, retry)."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"2","label":"stacks are enough for undo/redo","hint":"executed and undone commands"},{"value":"1","label":"method the invoker knows","hint":"execute() – the rest lives in the command"},{"value":"∞","label":"ways to use a request object","hint":"queue, log, macro, retry after a failure"}]}},{"type":"heading","attrs":{"level":2,"id":"the-problem-a-button-that-does-everything-itself"},"content":[{"type":"text","text":"The problem: a button that does everything itself"}]},{"type":"paragraph","content":[{"type":"text","text":"The terminal at the counter started with a single "},{"type":"text","text":"switch","marks":[{"type":"code"}]},{"type":"text","text":" handling buttons:"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"terminal-before.ts"},"content":[{"type":"text","text":"class Terminal {\n  constructor(private readonly ticket: Ticket) {}\n\n  onButton(action: string, payload: any): void {\n    switch (action) {\n      case 'add':      this.ticket.lines.push(payload); break;\n      case 'remove':   this.ticket.lines.splice(payload.index, 1); break;\n      case 'discount': this.ticket.discount = payload.percent; break;\n      // undo? \"Just delete the ticket and start again.\" – the waitress\n    }\n  }\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"The action logic lives in the button handler, so it cannot be used from anywhere else – say, from a keyboard shortcut or a phone app. There is no trace of what was done, so there is no undo. Nor can an action be postponed: when the kitchen printer is offline the order is lost, because the \"action\" only existed as a method call."}]},{"type":"heading","attrs":{"level":2,"id":"the-solution-every-action-is-an-object"},"content":[{"type":"text","text":"The solution: every action is an object"}]},{"type":"paragraph","content":[{"type":"text","text":"Every operation on the ticket becomes a class with an "},{"type":"text","text":"execute()","marks":[{"type":"code"}]},{"type":"text","text":" method (and optionally "},{"type":"text","text":"undo()","marks":[{"type":"code"}]},{"type":"text","text":"). The command object holds a reference to the "},{"type":"text","text":"receiver","marks":[{"type":"bold"}]},{"type":"text","text":" (the ticket) and all parameters. The terminal – the "},{"type":"text","text":"invoker","marks":[{"type":"bold"}]},{"type":"text","text":" – only runs commands and pushes them onto a history stack. Undo means popping a command off the stack and calling its "},{"type":"text","text":"undo()","marks":[{"type":"code"}]},{"type":"text","text":"."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  actor W as Waitress\n  participant T as Terminal (invoker)\n  participant A as AddDish(Kompot)\n  participant B as Ticket (receiver)\n  W->>T: run(new AddDish(Kompot))\n  T->>A: execute()\n  A->>B: lines.add(Kompot x1)\n  Note over T: history: [Ruskie, Kompot]\n  W->>T: undo()\n  T->>A: undo()\n  A->>B: remove the last line\n  Note over T: to redo: [Kompot]\n  W->>T: redo()\n  T->>A: execute()","caption":"Running, undoing and redoing commands"}},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  direction LR\n  class Terminal {\n    -done: Stack~Command~\n    -undone: Stack~Command~\n    +run(command)\n    +undo()\n    +redo()\n  }\n  class Command {\n    <<interface>>\n    +execute()\n    +undo()\n  }\n  class AddDish {\n    -ticket: Ticket\n    -dish, qty\n  }\n  class SetDiscount {\n    -ticket: Ticket\n    -percent\n    -previous\n  }\n  class Ticket {\n    +lines\n    +discountPercent\n  }\n  Terminal o--> Command\n  Command <|.. AddDish\n  Command <|.. SetDiscount\n  AddDish --> Ticket\n  SetDiscount --> Ticket","caption":"Participants of the Command 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":"Command"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Command","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the "},{"type":"text","text":"execute()","marks":[{"type":"code"}]},{"type":"text","text":" / "},{"type":"text","text":"undo()","marks":[{"type":"code"}]},{"type":"text","text":" interface"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Concrete command"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"AddDish","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"SetDiscount","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the request parameters and the knowledge of how to execute and undo it"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Receiver"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Ticket","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the object the command actually works on"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Invoker"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Terminal","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"runs commands and keeps the history"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Client"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the button handler"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"creates a command and hands it to the invoker"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"implementation-in-five-languages"},"content":[{"type":"text","text":"Implementation in five languages"}]},{"type":"paragraph","content":[{"type":"text","text":"Every variant runs the same scenario: two lines, a discount, two undos and one redo. In TypeScript commands are plain objects created by functions, and the "},{"type":"text","text":"label","marks":[{"type":"code"}]},{"type":"text","text":" shows that a command is also "},{"type":"text","text":"data","marks":[{"type":"bold"}]},{"type":"text","text":" – you can display the history or send it over the network."}]},{"type":"codeGroup","attrs":{"title":"Command – waiter's terminal"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"Terminal.cs"},"content":[{"type":"text","text":"var ticket = new Ticket();\nvar terminal = new Terminal();\nterminal.Run(new AddDish(ticket, \"Ruskie\", 2));\nterminal.Run(new AddDish(ticket, \"Kompot\", 1));\nterminal.Run(new SetDiscount(ticket, 10));\nterminal.Undo();           // discount removed\nterminal.Undo();           // kompot removed\nterminal.Redo();           // kompot is back\nConsole.WriteLine(ticket); // Ruskie x2, Kompot x1, discount 0%\n\npublic interface ICommand\n{\n    void Execute();\n    void Undo();\n}\n\npublic sealed class Ticket\n{\n    public List<(string Dish, int Qty)> Lines { get; } = [];\n    public int DiscountPercent { get; set; }\n\n    public override string ToString() =>\n        $\"{string.Join(\", \", Lines.Select(l => $\"{l.Dish} x{l.Qty}\"))}, discount {DiscountPercent}%\";\n}\n\npublic sealed class AddDish(Ticket ticket, string dish, int qty) : ICommand\n{\n    public void Execute() => ticket.Lines.Add((dish, qty));\n    public void Undo() => ticket.Lines.RemoveAt(ticket.Lines.Count - 1); // undo runs in LIFO order\n}\n\npublic sealed class SetDiscount(Ticket ticket, int percent) : ICommand\n{\n    private int _previous; // what Undo needs to restore\n\n    public void Execute() => (_previous, ticket.DiscountPercent) = (ticket.DiscountPercent, percent);\n    public void Undo() => ticket.DiscountPercent = _previous;\n}\n\npublic sealed class Terminal\n{\n    private readonly Stack<ICommand> _done = new();\n    private readonly Stack<ICommand> _undone = new();\n\n    public void Run(ICommand command)\n    {\n        command.Execute();\n        _done.Push(command);\n        _undone.Clear(); // a new action invalidates the redo history\n    }\n\n    public void Undo() { if (_done.TryPop(out var c)) { c.Undo(); _undone.Push(c); } }\n\n    public void Redo() { if (_undone.TryPop(out var c)) { c.Execute(); _done.Push(c); } }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"terminal.ts"},"content":[{"type":"text","text":"interface Command {\n  readonly label: string; // commands are data: they can be listed, logged, sent\n  execute(): void;\n  undo(): void;\n}\n\nclass Ticket {\n  lines: { dish: string; qty: number }[] = [];\n  discountPercent = 0;\n}\n\nconst addDish = (ticket: Ticket, dish: string, qty: number): Command => ({\n  label: `add ${dish} x${qty}`,\n  execute: () => void ticket.lines.push({ dish, qty }),\n  undo: () => void ticket.lines.pop(), // undo runs in LIFO order\n});\n\nconst setDiscount = (ticket: Ticket, percent: number): Command => {\n  let previous = 0;\n  return {\n    label: `discount ${percent}%`,\n    execute: () => { previous = ticket.discountPercent; ticket.discountPercent = percent; },\n    undo: () => { ticket.discountPercent = previous; },\n  };\n};\n\nclass Terminal {\n  private done: Command[] = [];\n  private undone: Command[] = [];\n\n  run(command: Command): void {\n    command.execute();\n    this.done.push(command);\n    this.undone = []; // a new action invalidates the redo history\n  }\n\n  undo(): void {\n    const command = this.done.pop();\n    if (command) { command.undo(); this.undone.push(command); }\n  }\n\n  redo(): void {\n    const command = this.undone.pop();\n    if (command) { command.execute(); this.done.push(command); }\n  }\n\n  get history(): string[] { return this.done.map((c) => c.label); }\n}\n\nconst ticket = new Ticket();\nconst terminal = new Terminal();\nterminal.run(addDish(ticket, 'Ruskie', 2));\nterminal.run(addDish(ticket, 'Kompot', 1));\nterminal.run(setDiscount(ticket, 10));\nterminal.undo();\nconsole.log(terminal.history); // ['add Ruskie x2', 'add Kompot x1']"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"Terminal.java"},"content":[{"type":"text","text":"import java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Deque;\nimport java.util.List;\n\ninterface Command {\n    void execute();\n    void undo();\n}\n\nclass Ticket {\n    final List<String> lines = new ArrayList<>();\n    int discountPercent;\n\n    @Override public String toString() { return lines + \", discount \" + discountPercent + \"%\"; }\n}\n\nrecord AddDish(Ticket ticket, String dish, int qty) implements Command {\n    public void execute() { ticket.lines.add(dish + \" x\" + qty); }\n    public void undo() { ticket.lines.removeLast(); } // undo runs in LIFO order (Java 21+)\n}\n\nfinal class SetDiscount implements Command {\n    private final Ticket ticket;\n    private final int percent;\n    private int previous; // what undo needs to restore\n\n    SetDiscount(Ticket ticket, int percent) { this.ticket = ticket; this.percent = percent; }\n\n    public void execute() { previous = ticket.discountPercent; ticket.discountPercent = percent; }\n    public void undo() { ticket.discountPercent = previous; }\n}\n\npublic class Terminal {\n    private final Deque<Command> done = new ArrayDeque<>();\n    private final Deque<Command> undone = new ArrayDeque<>();\n\n    public void run(Command command) {\n        command.execute();\n        done.push(command);\n        undone.clear(); // a new action invalidates the redo history\n    }\n\n    public void undo() { var c = done.poll(); if (c != null) { c.undo(); undone.push(c); } }\n\n    public void redo() { var c = undone.poll(); if (c != null) { c.execute(); done.push(c); } }\n\n    public static void main(String[] args) {\n        var ticket = new Ticket();\n        var terminal = new Terminal();\n        terminal.run(new AddDish(ticket, \"Ruskie\", 2));\n        terminal.run(new AddDish(ticket, \"Kompot\", 1));\n        terminal.run(new SetDiscount(ticket, 10));\n        terminal.undo();\n        terminal.undo();\n        terminal.redo();\n        System.out.println(ticket); // [Ruskie x2, Kompot x1], discount 0%\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"terminal.go"},"content":[{"type":"text","text":"package main\n\nimport \"fmt\"\n\ntype Command interface {\n\tExecute()\n\tUndo()\n}\n\ntype Ticket struct {\n\tLines           []string\n\tDiscountPercent int\n}\n\ntype AddDish struct {\n\tT    *Ticket\n\tDish string\n\tQty  int\n}\n\nfunc (c AddDish) Execute() { c.T.Lines = append(c.T.Lines, fmt.Sprintf(\"%s x%d\", c.Dish, c.Qty)) }\nfunc (c AddDish) Undo()    { c.T.Lines = c.T.Lines[:len(c.T.Lines)-1] } // undo runs in LIFO order\n\ntype SetDiscount struct {\n\tT        *Ticket\n\tPercent  int\n\tprevious int // what Undo needs to restore\n}\n\nfunc (c *SetDiscount) Execute() { c.previous, c.T.DiscountPercent = c.T.DiscountPercent, c.Percent }\nfunc (c *SetDiscount) Undo()    { c.T.DiscountPercent = c.previous }\n\ntype Terminal struct{ done, undone []Command }\n\nfunc (t *Terminal) Run(c Command) {\n\tc.Execute()\n\tt.done = append(t.done, c)\n\tt.undone = nil // a new action invalidates the redo history\n}\n\nfunc move(from, to *[]Command, act func(Command)) {\n\tif len(*from) == 0 {\n\t\treturn\n\t}\n\tc := (*from)[len(*from)-1]\n\t*from = (*from)[:len(*from)-1]\n\tact(c)\n\t*to = append(*to, c)\n}\n\nfunc (t *Terminal) Undo() { move(&t.done, &t.undone, Command.Undo) }\nfunc (t *Terminal) Redo() { move(&t.undone, &t.done, Command.Execute) }\n\nfunc main() {\n\tticket := &Ticket{}\n\tvar term Terminal\n\tterm.Run(AddDish{ticket, \"Ruskie\", 2})\n\tterm.Run(AddDish{ticket, \"Kompot\", 1})\n\tterm.Run(&SetDiscount{T: ticket, Percent: 10})\n\tterm.Undo()\n\tterm.Undo()\n\tterm.Redo()\n\tfmt.Println(ticket.Lines, ticket.DiscountPercent) // [Ruskie x2 Kompot x1] 0\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"terminal.py"},"content":[{"type":"text","text":"from dataclasses import dataclass, field\nfrom typing import Protocol\n\n\nclass Command(Protocol):\n    def execute(self) -> None: ...\n    def undo(self) -> None: ...\n\n\n@dataclass\nclass Ticket:\n    lines: list[str] = field(default_factory=list)\n    discount_percent: int = 0\n\n\n@dataclass\nclass AddDish:\n    ticket: Ticket\n    dish: str\n    qty: int\n\n    def execute(self) -> None:\n        self.ticket.lines.append(f\"{self.dish} x{self.qty}\")\n\n    def undo(self) -> None:\n        self.ticket.lines.pop()  # undo runs in LIFO order\n\n\n@dataclass\nclass SetDiscount:\n    ticket: Ticket\n    percent: int\n    _previous: int = field(default=0, init=False, repr=False)  # what undo needs to restore\n\n    def execute(self) -> None:\n        self._previous, self.ticket.discount_percent = self.ticket.discount_percent, self.percent\n\n    def undo(self) -> None:\n        self.ticket.discount_percent = self._previous\n\n\nclass Terminal:\n    def __init__(self) -> None:\n        self._done: list[Command] = []\n        self._undone: list[Command] = []\n\n    def run(self, command: Command) -> None:\n        command.execute()\n        self._done.append(command)\n        self._undone.clear()  # a new action invalidates the redo history\n\n    def undo(self) -> None:\n        if self._done:\n            command = self._done.pop()\n            command.undo()\n            self._undone.append(command)\n\n    def redo(self) -> None:\n        if self._undone:\n            command = self._undone.pop()\n            command.execute()\n            self._done.append(command)\n\n\nticket, terminal = Ticket(), Terminal()\nterminal.run(AddDish(ticket, \"Ruskie\", 2))\nterminal.run(AddDish(ticket, \"Kompot\", 1))\nterminal.run(SetDiscount(ticket, 10))\nterminal.undo()\nterminal.undo()\nterminal.redo()\nprint(ticket)  # Ticket(lines=['Ruskie x2', 'Kompot x1'], discount_percent=0)"}]}]}]},"toc":[{"id":"the-problem-a-button-that-does-everything-itself","text":"The problem: a button that does everything itself","level":2,"locked":false},{"id":"the-solution-every-action-is-an-object","text":"The solution: every action is an object","level":2,"locked":false},{"id":"implementation-in-five-languages","text":"Implementation in five languages","level":2,"locked":false},{"id":"two-ways-to-undo","text":"Two ways to undo","level":2,"locked":true},{"id":"inverse-operation","text":"Inverse operation","level":3,"locked":true},{"id":"state-snapshot","text":"State snapshot","level":3,"locked":true},{"id":"command-as-data-queues-and-retries","text":"Command as data: queues and retries","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":"command-vs-a-command-in-cqrs","text":"Command vs a command in CQRS","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}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":38,"visibleBlocks":15,"resources":[{"id":"6b0857a53c96f2d34d0b3220","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=9qA5kw8dcSU","embedUrl":"https://www.youtube-nocookie.com/embed/9qA5kw8dcSU","title":"Command Pattern – Design Patterns (ep 7)","description":"","author":"Christopher Okhravi","thumbnailUrl":"https://i.ytimg.com/vi/9qA5kw8dcSU/hqdefault.jpg","durationSec":null,"lang":"en","topics":["command"],"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.889Z","updatedAt":"2026-11-26T16:00:37.889Z"},{"id":"6b0857bf3c96f2d34d0b4269","type":"article","provider":"web","url":"https://gameprogrammingpatterns.com/command.html","embedUrl":null,"title":"Command · Design Patterns Revisited · Game Programming Patterns","description":"","author":"Robert Nystrom","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["command"],"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.277Z"},{"id":"6b0857bf3c96f2d34d0b4286","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/command","embedUrl":null,"title":"Polecenie / Command","description":"Polecenie jest behawioralnym wzorcem projektowym który zmienia żądanie w samodzielny obiekt zawierający wszystkie informacje o tym żądaniu. Taka transformacja pozwala na parametryzowanie metod przy użyciu różnych żądań. Oprócz tego umożliwia opóźnianie lub kolejkowanie wykonywania żądań oraz…","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["command"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":65,"verifiedAt":"2026-11-26T11:26:12.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857c33c96f2d34d0b4685","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL19650342W","embedUrl":null,"title":"Game Programming Patterns","description":"","author":"Robert Nystrom","thumbnailUrl":"https://covers.openlibrary.org/b/id/8566115-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":["general"],"tags":["book"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"2011-01-01T00:00:00.000Z","popularity":54,"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"},{"id":"6b0857bb3c96f2d34d0b3f54","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/command-repository-and-mediator-design-patterns/id769189585?i=1000378375285","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id769189585?i=1000378375285","title":"Command, Repository and Mediator Design Patterns","description":"In this episode we go back to the design pattern well that we’ve been away from for so long. We cover the Command, Repository and Mediator design patterns. It was hard for us to believe, but it’s been almost a year since our last design patterns episode!!! Come on in for fun, learning, and of […]","author":"Coding Blocks","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts113/v4/f0/b6/68/f0b6682f-e8bc-181c-95a9-0756ddf63d6e/mza_3128980961332034780.jpg/600x600bb.jpg","durationSec":7684,"lang":"en","topics":["mediator"],"techs":["general"],"tags":["podcast","design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2016-06-03T03:52:46.000Z","popularity":49,"verifiedAt":"2026-11-26T10:57:23.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:57.868Z","updatedAt":"2026-11-26T16:00:57.868Z"}],"challenges":[{"id":"6b093dc291bd8fbaf2a0c8e8","slug":"text-editor-undo","title":"Undo and redo in a text editor","summary":"Editor operations as commands with execute() and undo(), a history with undo and redo, macros undone in one step and a limit on remembered changes.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"medium","topics":["command"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["command","undo-redo","macro","text-editor","behavioral"],"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:26.885Z"},{"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":"6b093dc091bd8fbaf2a0c8c0","slug":"event-sourced-account","title":"Event-sourced bank account","summary":"An account aggregate whose state comes only from replaying events, an event store with optimistic concurrency and a repository that saves only new facts. Queries about past state come for free.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"architecture","status":"published","difficulty":"hard","topics":["event-sourcing","cqrs"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["event-sourcing","aggregate","event-store","optimistic-concurrency","ddd"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":40,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:24.935Z"}],"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":false},{"slug":"command","title":"Command: a request wrapped in an object","current":true},{"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":"observer","title":"Observer: notify everyone without knowing anyone"},"next":{"slug":"state","title":"State: an object that changes behaviour with its life stage"},"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":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}