{"id":"6b08bd3080884893657cc910","slug":"command","title":"Polecenie (Command): żądanie zamknięte w obiekcie","summary":"Wzorzec Polecenie na przykładzie terminala kelnerskiego w pierogarni: każda akcja na bonie to obiekt z metodami execute i undo, więc da się ją cofnąć, ponowić, zapisać w historii i wysłać do kolejki. Kod w pięciu językach.","servedLang":"pl","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":11,"stats":{"views":1,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:52.954Z","updatedAt":"2026-11-27T10:04:46.685Z","requestedLang":"pl","theme":{"hero":"classic","heroMedia":null,"accent":"violet","background":"hex","weaveResources":true,"toc":"right"},"seoDescription":"Wzorzec projektowy Polecenie (Command) w C#, TypeScript, Java, Go i Python: cofanie i ponawianie (undo/redo), kolejki zadań, makra i różnica względem komend w CQRS.","wordCount":2148,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Kelnerka w pierogarni Haliny dopisuje do bonu dwie porcje ruskich, kompot i rabat dla stałego klienta. Klient się rozmyśla – kompot ma zniknąć, ale ruskie zostają. "},{"type":"text","text":"Polecenie","marks":[{"type":"bold"}]},{"type":"text","text":" (ang. "},{"type":"text","text":"Command","marks":[{"type":"italic"}]},{"type":"text","text":") zamienia każde kliknięcie w obiekt, który wie, jak się wykonać i jak się cofnąć. Dzięki temu cofanie, historia i kolejka do kuchni przestają być osobnymi problemami."}]},{"type":"callout","attrs":{"variant":"tip","title":"W skrócie"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Polecenie "},{"type":"text","text":"zamyka żądanie w obiekcie","marks":[{"type":"bold"}]},{"type":"text","text":": kto ma coś zrobić (odbiorca), co i z jakimi parametrami."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Wywołujący ("},{"type":"text","text":"invoker","marks":[{"type":"italic"}]},{"type":"text","text":") uruchamia polecenia, nie znając ich treści – zna tylko "},{"type":"text","text":"execute()","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Skoro żądanie jest obiektem, można je "},{"type":"text","text":"przechować","marks":[{"type":"bold"}]},{"type":"text","text":": w historii (cofanie), w kolejce (później), w logu (audyt, ponowienie)."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"2","label":"stosy wystarczą do undo/redo","hint":"wykonane i cofnięte polecenia"},{"value":"1","label":"metoda, którą zna wywołujący","hint":"execute() – reszta jest w poleceniu"},{"value":"∞","label":"sposobów użycia obiektu-żądania","hint":"kolejka, log, makro, ponowienie po awarii"}]}},{"type":"heading","attrs":{"level":2,"id":"problem-przycisk-ktory-robi-wszystko-sam"},"content":[{"type":"text","text":"Problem: przycisk, który robi wszystko sam"}]},{"type":"paragraph","content":[{"type":"text","text":"Terminal przy kasie zaczynał od jednego "},{"type":"text","text":"switch","marks":[{"type":"code"}]},{"type":"text","text":"a obsługującego przyciski:"}]},{"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":"Logika akcji siedzi w obsłudze przycisków, więc nie da się jej użyć z innego miejsca – na przykład ze skrótu klawiszowego albo z aplikacji na telefon. Nie ma śladu tego, co zrobiono, więc nie ma cofania. Nie da się też odłożyć akcji na później: gdy drukarka w kuchni jest offline, zamówienie przepada, bo „akcja” istniała tylko jako wywołanie metody."}]},{"type":"heading","attrs":{"level":2,"id":"rozwiazanie-kazda-akcja-to-obiekt"},"content":[{"type":"text","text":"Rozwiązanie: każda akcja to obiekt"}]},{"type":"paragraph","content":[{"type":"text","text":"Każda operacja na bonie staje się klasą z metodą "},{"type":"text","text":"execute()","marks":[{"type":"code"}]},{"type":"text","text":" (i opcjonalnie "},{"type":"text","text":"undo()","marks":[{"type":"code"}]},{"type":"text","text":"). Obiekt polecenia trzyma referencję do "},{"type":"text","text":"odbiorcy","marks":[{"type":"bold"}]},{"type":"text","text":" (bonu) i wszystkie parametry. Terminal – "},{"type":"text","text":"wywołujący","marks":[{"type":"bold"}]},{"type":"text","text":" – tylko uruchamia polecenia i odkłada je na stos historii. Cofnięcie to zdjęcie polecenia ze stosu i wywołanie jego "},{"type":"text","text":"undo()","marks":[{"type":"code"}]},{"type":"text","text":"."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  actor W as Kelnerka\n  participant T as Terminal (invoker)\n  participant A as AddDish(Kompot)\n  participant B as Ticket (odbiorca)\n  W->>T: run(new AddDish(Kompot))\n  T->>A: execute()\n  A->>B: lines.add(Kompot x1)\n  Note over T: historia: [Ruskie, Kompot]\n  W->>T: undo()\n  T->>A: undo()\n  A->>B: usuń ostatnią pozycję\n  Note over T: do ponowienia: [Kompot]\n  W->>T: redo()\n  T->>A: execute()","caption":"Uruchamianie, cofanie i ponawianie poleceń"}},{"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":"Uczestnicy wzorca Polecenie"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Rola"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"W przykładzie"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Odpowiedzialność"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Polecenie ("},{"type":"text","text":"Command","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"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":"interfejs "},{"type":"text","text":"execute()","marks":[{"type":"code"}]},{"type":"text","text":" / "},{"type":"text","text":"undo()","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Konkretne polecenie"}]}]},{"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":"parametry żądania i wiedza, jak je wykonać i cofnąć"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Odbiorca ("},{"type":"text","text":"Receiver","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"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":"obiekt, na którym polecenie faktycznie działa"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Wywołujący ("},{"type":"text","text":"Invoker","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"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":"uruchamia polecenia, prowadzi historię"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Klient"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"obsługa przycisku"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"tworzy polecenie i przekazuje je wywołującemu"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"implementacja-w-pieciu-jezykach"},"content":[{"type":"text","text":"Implementacja w pięciu językach"}]},{"type":"paragraph","content":[{"type":"text","text":"Każdy wariant ma ten sam scenariusz: dwie pozycje, rabat, dwa cofnięcia i jedno ponowienie. W TypeScripcie polecenia są zwykłymi obiektami tworzonymi przez funkcje, a etykieta "},{"type":"text","text":"label","marks":[{"type":"code"}]},{"type":"text","text":" pokazuje, że polecenie to także "},{"type":"text","text":"dane","marks":[{"type":"bold"}]},{"type":"text","text":" – można wyświetlić historię albo wysłać ją przez sieć."}]},{"type":"codeGroup","attrs":{"title":"Polecenie – terminal kelnerski"},"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":"problem-przycisk-ktory-robi-wszystko-sam","text":"Problem: przycisk, który robi wszystko sam","level":2,"locked":false},{"id":"rozwiazanie-kazda-akcja-to-obiekt","text":"Rozwiązanie: każda akcja to obiekt","level":2,"locked":false},{"id":"implementacja-w-pieciu-jezykach","text":"Implementacja w pięciu językach","level":2,"locked":false},{"id":"dwa-sposoby-na-cofanie","text":"Dwa sposoby na cofanie","level":2,"locked":true},{"id":"operacja-odwrotna","text":"Operacja odwrotna","level":3,"locked":true},{"id":"migawka-stanu","text":"Migawka stanu","level":3,"locked":true},{"id":"polecenie-jako-dane-kolejki-i-ponowienia","text":"Polecenie jako dane: kolejki i ponowienia","level":2,"locked":true},{"id":"kiedy-stosowac-a-kiedy-nie","text":"Kiedy stosować, a kiedy nie","level":2,"locked":true},{"id":"polecenie-a-komenda-w-cqrs","text":"Polecenie a komenda w CQRS","level":2,"locked":true},{"id":"powiazania-z-innymi-wzorcami","text":"Powiązania z innymi wzorcami","level":2,"locked":true},{"id":"w-praktyce","text":"W praktyce","level":2,"locked":true},{"id":"sprawdz-sie","text":"Sprawdź się","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":"Cofnij i ponów w edytorze tekstu","summary":"Operacje edytora jako polecenia z execute() i undo(), historia z cofaniem i ponawianiem, makra cofane jednym krokiem i limit pamiętanych zmian.","servedLang":"pl","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":"Magazyn z CQRS – osobny model zapisu i odczytu","summary":"Komendy magazynowe walidowane na własnym modelu zapisu, zdarzenia na szynie i projekcja budująca model odczytu z raportem niskich stanów. Model odczytu da się odtworzyć z samych zdarzeń.","servedLang":"pl","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":"Konto bankowe w event sourcingu","summary":"Agregat konta, którego stan powstaje wyłącznie z odtwarzania zdarzeń, magazyn zdarzeń z optymistyczną współbieżnością i repozytorium zapisujące tylko nowe fakty. Zapytania o stan z przeszłości w gratisie.","servedLang":"pl","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":"Wzorce behawioralne GoF","items":[{"slug":"strategy","title":"Strategia (Strategy): wymienne algorytmy zamiast drabinki if-ów","current":false},{"slug":"observer","title":"Obserwator (Observer): powiadom wszystkich, nie znając nikogo","current":false},{"slug":"command","title":"Polecenie (Command): żądanie zamknięte w obiekcie","current":true},{"slug":"state","title":"Stan (State): obiekt, który zmienia zachowanie razem z etapem życia","current":false},{"slug":"template-method","title":"Metoda szablonowa (Template Method): stały przepis, wymienne składniki","current":false},{"slug":"iterator","title":"Iterator: przechodzenie po kolekcji bez zaglądania do środka","current":false},{"slug":"chain-of-responsibility","title":"Łańcuch zobowiązań (Chain of Responsibility): podaj dalej, aż ktoś się zajmie","current":false},{"slug":"mediator","title":"Mediator: komponenty rozmawiają przez koordynatora","current":false},{"slug":"memento","title":"Pamiątka (Memento): migawka stanu bez łamania hermetyzacji","current":false},{"slug":"visitor","title":"Odwiedzający (Visitor): nowe operacje bez zmiany klas","current":false}]}],"prev":{"slug":"observer","title":"Obserwator (Observer): powiadom wszystkich, nie znając nikogo"},"next":{"slug":"state","title":"Stan (State): obiekt, który zmienia zachowanie razem z etapem życia"},"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":"Autorytet","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Autorytet","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Autorytet","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Autorytet","articles":38}]}}