{"id":"6b08bd3180884893657cc91a","slug":"composite","title":"Kompozyt (Composite) – drzewa, w których liść i gałąź wyglądają tak samo","summary":"Kompozyt pozwala traktować pojedynczy obiekt i całą grupę obiektów w identyczny sposób. Przykład programu kursu z modułami i lekcjami w C#, TypeScript, Javie, Go i Pythonie.","servedLang":"pl","availableLangs":["pl","en"],"topics":["composite","decorator","iterator","visitor"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","structural","composite","tree","recursion"],"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":10,"stats":{"views":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:53.346Z","updatedAt":"2026-11-27T10:05:02.633Z","requestedLang":"pl","theme":{"hero":"classic","heroMedia":null,"accent":"indigo","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"Wzorzec Kompozyt (Composite) – struktury drzewiaste, komponent, liść i kompozyt, przejrzystość kontra bezpieczeństwo, diagramy, kod w C#, TypeScript, Java, Go i Python, przykłady z Swing, io.MultiWriter, unittest i DOM.","wordCount":1901,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Menu z podmenu, katalogi z plikami, dział firmy z zespołami, kurs z modułami i lekcjami – drzewa są wszędzie. "},{"type":"text","text":"Kompozyt","marks":[{"type":"bold"}]},{"type":"text","text":" (ang. "},{"type":"text","text":"Composite","marks":[{"type":"italic"}]},{"type":"text","text":") sprawia, że kod operujący na drzewie nie musi pytać „czy to liść, czy gałąź?”: oba mają ten sam interfejs, a gałąź po prostu przekazuje wywołanie swoim dzieciom."}]},{"type":"callout","attrs":{"variant":"info","title":"W skrócie"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Liść (lekcja) i kompozyt (sekcja) implementują wspólny interfejs komponentu."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Kompozyt przechowuje dzieci typu komponent i agreguje ich wyniki – rekurencja robi resztę."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Klient wywołuje "},{"type":"text","text":"minutes()","marks":[{"type":"code"}]},{"type":"text","text":" na całym kursie dokładnie tak samo jak na pojedynczej lekcji."}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"problem-ile-trwa-ten-kurs"},"content":[{"type":"text","text":"Problem: ile trwa ten kurs?"}]},{"type":"paragraph","content":[{"type":"text","text":"Platforma kursów programowania pokazuje przy każdym kursie łączny czas nagrań. Kurs składa się z lekcji i sekcji, a sekcje mogą zawierać kolejne sekcje – autorzy lubią „bonusy w bonusach”. Pierwsza implementacja:"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"course-duration.ts"},"content":[{"type":"text","text":"function totalMinutes(items: (Lesson | Section)[]): number {\n  let total = 0;\n  for (const item of items) {\n    if (item instanceof Lesson) total += item.minutes;\n    else if (item instanceof Section) total += totalMinutes(item.children);\n    // a new node type (Quiz? LiveSession?) means another branch – here and everywhere else\n  }\n  return total;\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"Ta sama drabinka "},{"type":"text","text":"instanceof","marks":[{"type":"code"}]},{"type":"text","text":" pojawia się w drukowaniu spisu treści, liczeniu lekcji, eksporcie do PDF i sprawdzaniu postępu. Każdy nowy typ węzła – quiz, sesja na żywo – wymaga poprawek we wszystkich tych miejscach."}]},{"type":"heading","attrs":{"level":2,"id":"rozwiazanie-wspolny-interfejs-dla-liscia-i-galezi"},"content":[{"type":"text","text":"Rozwiązanie: wspólny interfejs dla liścia i gałęzi"}]},{"type":"paragraph","content":[{"type":"text","text":"Definiujemy interfejs "},{"type":"text","text":"CurriculumItem","marks":[{"type":"code"}]},{"type":"text","text":" z operacjami, które mają sens dla każdego węzła: "},{"type":"text","text":"minutes()","marks":[{"type":"code"}]},{"type":"text","text":" i "},{"type":"text","text":"print()","marks":[{"type":"code"}]},{"type":"text","text":". "},{"type":"text","text":"Lesson","marks":[{"type":"code"}]},{"type":"text","text":" (liść) odpowiada sam za siebie. "},{"type":"text","text":"Section","marks":[{"type":"code"}]},{"type":"text","text":" (kompozyt) trzyma listę dzieci typu "},{"type":"text","text":"CurriculumItem","marks":[{"type":"code"}]},{"type":"text","text":" i implementuje te same metody, delegując do dzieci i sumując wyniki. Klient nie odróżnia jednego od drugiego."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  direction LR\n  class CurriculumItem {\n    <<interface>>\n    +title\n    +minutes() int\n    +print(depth)\n  }\n  class Lesson {\n    +minutes() int\n    +print(depth)\n  }\n  class Section {\n    -children List~CurriculumItem~\n    +minutes() int\n    +print(depth)\n  }\n  CurriculumItem <|.. Lesson\n  CurriculumItem <|.. Section\n  Section o-- \"0..*\" CurriculumItem : dzieci","caption":"Struktura Kompozytu"}},{"type":"paragraph","content":[{"type":"text","text":"Tak wygląda drzewo z naszego przykładu. Czas każdej sekcji to suma czasów jej dzieci – liczona rekurencyjnie, bez ani jednego "},{"type":"text","text":"instanceof","marks":[{"type":"code"}]},{"type":"text","text":":"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart TD\n  C[\"Kurs: Design Patterns · 72 min\"] --> L1[\"Welcome · 5\"]\n  C --> S1[\"Creational · 40\"]\n  C --> S2[\"Structural · 27\"]\n  S1 --> L2[\"Factory Method · 18\"]\n  S1 --> L3[\"Builder · 22\"]\n  S2 --> L4[\"Adapter · 15\"]\n  S2 --> S3[\"Bonus · 12\"]\n  S3 --> L5[\"Composite in UI trees · 12\"]","caption":"Przykładowy kurs jako drzewo – sekcje sumują czas dzieci"}},{"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":"Komponent ("},{"type":"text","text":"Component","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"CurriculumItem","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"wspólny interfejs liści i kompozytów"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Liść ("},{"type":"text","text":"Leaf","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Lesson","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"wykonuje właściwą pracę, nie ma dzieci"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Kompozyt ("},{"type":"text","text":"Composite","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Section","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"przechowuje dzieci, deleguje do nich i agreguje wyniki"}]}]}]},{"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":"widok kursu"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"operuje na komponentach, nie znając ich rodzaju"}]}]}]}]},{"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":"W Javie interfejs jest zapieczętowany ("},{"type":"text","text":"sealed","marks":[{"type":"code"}]},{"type":"text","text":") – kompilator zna wszystkie rodzaje węzłów, co przydaje się przy dopasowaniu wzorców w "},{"type":"text","text":"switch","marks":[{"type":"code"}]},{"type":"text","text":". W Go liść i kompozyt to zwykłe struktury spełniające ten sam interfejs, a w Pythonie wystarczy "},{"type":"text","text":"Protocol","marks":[{"type":"code"}]},{"type":"text","text":"."}]},{"type":"codeGroup","attrs":{"title":"ICurriculumItem"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"Curriculum.cs"},"content":[{"type":"text","text":"var course = new Section(\"Design Patterns\",\n[\n    new Lesson(\"Welcome\", 5),\n    new Section(\"Creational\", [new Lesson(\"Factory Method\", 18), new Lesson(\"Builder\", 22)]),\n    new Section(\"Structural\",\n    [\n        new Lesson(\"Adapter\", 15),\n        new Section(\"Bonus\", [new Lesson(\"Composite in UI trees\", 12)]),\n    ]),\n]);\n\ncourse.Print();\nConsole.WriteLine($\"Total: {course.Minutes} min\"); // 72\n\n// Component: a leaf and a branch look the same to the client.\npublic interface ICurriculumItem\n{\n    string Title { get; }\n    int Minutes { get; }\n    void Print(int depth = 0);\n}\n\n// Leaf: does the real work.\npublic sealed record Lesson(string Title, int Minutes) : ICurriculumItem\n{\n    public void Print(int depth = 0) =>\n        Console.WriteLine($\"{new string(' ', depth * 2)}- {Title} ({Minutes} min)\");\n}\n\n// Composite: delegates to its children and aggregates their results.\npublic sealed class Section(string title, IReadOnlyList<ICurriculumItem> children) : ICurriculumItem\n{\n    public string Title => title;\n    public int Minutes => children.Sum(child => child.Minutes);\n\n    public void Print(int depth = 0)\n    {\n        Console.WriteLine($\"{new string(' ', depth * 2)}+ {Title} ({Minutes} min)\");\n        foreach (var child in children) child.Print(depth + 1);\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"curriculum.ts"},"content":[{"type":"text","text":"// Component: a leaf and a branch look the same to the client.\ninterface CurriculumItem {\n  readonly title: string;\n  minutes(): number;\n  print(depth?: number): void;\n}\n\n// Leaf: does the real work.\nclass Lesson implements CurriculumItem {\n  constructor(readonly title: string, private readonly length: number) {}\n\n  minutes(): number {\n    return this.length;\n  }\n\n  print(depth = 0): void {\n    console.log(`${\"  \".repeat(depth)}- ${this.title} (${this.length} min)`);\n  }\n}\n\n// Composite: delegates to its children and aggregates their results.\nclass Section implements CurriculumItem {\n  constructor(readonly title: string, private readonly children: CurriculumItem[]) {}\n\n  minutes(): number {\n    return this.children.reduce((sum, child) => sum + child.minutes(), 0);\n  }\n\n  print(depth = 0): void {\n    console.log(`${\"  \".repeat(depth)}+ ${this.title} (${this.minutes()} min)`);\n    this.children.forEach((child) => child.print(depth + 1));\n  }\n}\n\nconst course = new Section(\"Design Patterns\", [\n  new Lesson(\"Welcome\", 5),\n  new Section(\"Creational\", [new Lesson(\"Factory Method\", 18), new Lesson(\"Builder\", 22)]),\n  new Section(\"Structural\", [\n    new Lesson(\"Adapter\", 15),\n    new Section(\"Bonus\", [new Lesson(\"Composite in UI trees\", 12)]),\n  ]),\n]);\n\ncourse.print();\nconsole.log(`Total: ${course.minutes()} min`); // 72"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"Curriculum.java"},"content":[{"type":"text","text":"import java.util.List;\n\n// Component: a sealed interface lists every kind of node in the tree.\nsealed interface CurriculumItem permits Lesson, Section {\n    String title();\n    int minutes();\n    void print(int depth);\n}\n\n// Leaf: does the real work.\nrecord Lesson(String title, int minutes) implements CurriculumItem {\n    public void print(int depth) {\n        System.out.println(\"  \".repeat(depth) + \"- \" + title + \" (\" + minutes + \" min)\");\n    }\n}\n\n// Composite: delegates to its children and aggregates their results.\nrecord Section(String title, List<CurriculumItem> children) implements CurriculumItem {\n    public int minutes() {\n        return children.stream().mapToInt(CurriculumItem::minutes).sum();\n    }\n\n    public void print(int depth) {\n        System.out.println(\"  \".repeat(depth) + \"+ \" + title + \" (\" + minutes() + \" min)\");\n        children.forEach(child -> child.print(depth + 1));\n    }\n}\n\npublic class Curriculum {\n    public static void main(String[] args) {\n        CurriculumItem course = new Section(\"Design Patterns\", List.of(\n            new Lesson(\"Welcome\", 5),\n            new Section(\"Creational\", List.of(new Lesson(\"Factory Method\", 18), new Lesson(\"Builder\", 22))),\n            new Section(\"Structural\", List.of(\n                new Lesson(\"Adapter\", 15),\n                new Section(\"Bonus\", List.of(new Lesson(\"Composite in UI trees\", 12)))))));\n\n        course.print(0);\n        System.out.println(\"Total: \" + course.minutes() + \" min\"); // 72\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"curriculum.go"},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\n// CurriculumItem is the component: a leaf and a branch look the same to the client.\ntype CurriculumItem interface {\n\tMinutes() int\n\tPrint(depth int)\n}\n\n// Lesson is a leaf: it does the real work.\ntype Lesson struct {\n\tTitle  string\n\tLength int\n}\n\nfunc (l Lesson) Minutes() int { return l.Length }\n\nfunc (l Lesson) Print(depth int) {\n\tfmt.Printf(\"%s- %s (%d min)\\n\", strings.Repeat(\"  \", depth), l.Title, l.Length)\n}\n\n// Section is the composite: it delegates to its children and aggregates their results.\ntype Section struct {\n\tTitle    string\n\tChildren []CurriculumItem\n}\n\nfunc (s Section) Minutes() int {\n\ttotal := 0\n\tfor _, child := range s.Children {\n\t\ttotal += child.Minutes()\n\t}\n\treturn total\n}\n\nfunc (s Section) Print(depth int) {\n\tfmt.Printf(\"%s+ %s (%d min)\\n\", strings.Repeat(\"  \", depth), s.Title, s.Minutes())\n\tfor _, child := range s.Children {\n\t\tchild.Print(depth + 1)\n\t}\n}\n\nfunc main() {\n\tcourse := Section{\"Design Patterns\", []CurriculumItem{\n\t\tLesson{\"Welcome\", 5},\n\t\tSection{\"Creational\", []CurriculumItem{Lesson{\"Factory Method\", 18}, Lesson{\"Builder\", 22}}},\n\t\tSection{\"Structural\", []CurriculumItem{\n\t\t\tLesson{\"Adapter\", 15},\n\t\t\tSection{\"Bonus\", []CurriculumItem{Lesson{\"Composite in UI trees\", 12}}},\n\t\t}},\n\t}}\n\tcourse.Print(0)\n\tfmt.Printf(\"Total: %d min\\n\", course.Minutes()) // 72\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"curriculum.py"},"content":[{"type":"text","text":"from dataclasses import dataclass, field\nfrom typing import Protocol\n\n\nclass CurriculumItem(Protocol):\n    \"\"\"Component: a leaf and a branch look the same to the client.\"\"\"\n\n    def minutes(self) -> int: ...\n    def print_tree(self, depth: int = 0) -> None: ...\n\n\n@dataclass(frozen=True)\nclass Lesson:\n    \"\"\"Leaf: does the real work.\"\"\"\n\n    title: str\n    length: int\n\n    def minutes(self) -> int:\n        return self.length\n\n    def print_tree(self, depth: int = 0) -> None:\n        print(f\"{'  ' * depth}- {self.title} ({self.length} min)\")\n\n\n@dataclass(frozen=True)\nclass Section:\n    \"\"\"Composite: delegates to its children and aggregates their results.\"\"\"\n\n    title: str\n    children: list[CurriculumItem] = field(default_factory=list)\n\n    def minutes(self) -> int:\n        return sum(child.minutes() for child in self.children)\n\n    def print_tree(self, depth: int = 0) -> None:\n        print(f\"{'  ' * depth}+ {self.title} ({self.minutes()} min)\")\n        for child in self.children:\n            child.print_tree(depth + 1)\n\n\nif __name__ == \"__main__\":\n    course = Section(\"Design Patterns\", [\n        Lesson(\"Welcome\", 5),\n        Section(\"Creational\", [Lesson(\"Factory Method\", 18), Lesson(\"Builder\", 22)]),\n        Section(\"Structural\", [\n            Lesson(\"Adapter\", 15),\n            Section(\"Bonus\", [Lesson(\"Composite in UI trees\", 12)]),\n        ]),\n    ])\n    course.print_tree()\n    print(f\"Total: {course.minutes()} min\")  # 72"}]}]}]},"toc":[{"id":"problem-ile-trwa-ten-kurs","text":"Problem: ile trwa ten kurs?","level":2,"locked":false},{"id":"rozwiazanie-wspolny-interfejs-dla-liscia-i-galezi","text":"Rozwiązanie: wspólny interfejs dla liścia i gałęzi","level":2,"locked":false},{"id":"implementacja-w-pieciu-jezykach","text":"Implementacja w pięciu językach","level":2,"locked":false},{"id":"przejrzystosc-czy-bezpieczenstwo","text":"Przejrzystość czy bezpieczeństwo?","level":2,"locked":true},{"id":"krok-po-kroku","text":"Krok po kroku","level":2,"locked":true},{"id":"kiedy-stosowac-a-kiedy-nie","text":"Kiedy stosować, a kiedy nie","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":"szybki-test","text":"Szybki test","level":2,"locked":true},{"id":"podsumowanie","text":"Podsumowanie","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":35,"visibleBlocks":15,"resources":[{"id":"6b0857c63c96f2d34d0b48e7","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=ss6je4-nDx8","embedUrl":"https://www.youtube-nocookie.com/embed/ss6je4-nDx8","title":"This Design Pattern Simplifies Everything","description":"🧱 Build software that lasts. Join the Software Design Mastery program → https://arjan.codes/mastery. The Composite pattern is one of those design patterns you'll start seeing everywhere once you understand it. In this video, I build a small game engine in Python to explore how the Composite…","author":"ArjanCodes","thumbnailUrl":"https://i.ytimg.com/vi/ss6je4-nDx8/hqdefault.jpg","durationSec":null,"lang":"en","topics":["composite"],"techs":["python"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"youtube-rss","publishedAt":"2026-08-07T15:00:28.000Z","popularity":68,"verifiedAt":"2026-11-26T10:54:44.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:10.095Z","updatedAt":"2026-11-26T16:01:10.095Z"},{"id":"6b0857be3c96f2d34d0b4231","type":"article","provider":"web","url":"https://refactoring.guru/design-patterns/composite","embedUrl":null,"title":"Composite","description":"Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"en","topics":["composite"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":70,"verifiedAt":"2026-11-26T11:26:02.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857b23c96f2d34d0b351e","type":"repo","provider":"github","url":"https://github.com/torokmark/design_patterns_in_typescript","embedUrl":null,"title":"torokmark/design_patterns_in_typescript","description":":triangular_ruler: Design pattern implementations in TypeScript","author":"torokmark","thumbnailUrl":"https://opengraph.githubassets.com/1/torokmark/design_patterns_in_typescript","durationSec":null,"lang":"en","topics":["builder","adapter","composite","facade","command"],"techs":["typescript"],"tags":["adapter","builder","command","composite","design-patterns","facade","typescript"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2013-07-07T21:49:06.000Z","popularity":72,"verifiedAt":"2026-11-26T10:57:25.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"},{"id":"6b0857c33c96f2d34d0b4658","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL6030812W","embedUrl":null,"title":"Design Patterns: Elements of Reusable Object-Oriented Software","description":"","author":"Erich Gamma, John Vlissides, Richard Helm, Ralph Johnson","thumbnailUrl":"https://covers.openlibrary.org/b/id/6601119-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","design-patterns"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"1995-01-01T00:00:00.000Z","popularity":71,"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":"6b0857af5a2625e44ecaad13","slug":"design-patterns-basics-quiz","title":"Wzorce projektowe – podstawy","summary":"Sześć pytań o klasyczne wzorce GoF: grupy, przeznaczenie i różnice.","servedLang":"pl","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"},{"id":"6b093ddebd4755deb67ee06e","slug":"flatten-object","title":"Spłaszczanie zagnieżdżonego obiektu","summary":"Zamieniamy zagnieżdżony obiekt JSON na płaską mapę ścieżka → wartość (np. do eksportu CSV albo porównania konfiguracji). Rekurencja lub jawny stos, liście i puste kontenery.","servedLang":"pl","availableLangs":["pl","en"],"kind":"code","category":"algorithms","status":"published","difficulty":"easy","topics":["composite"],"techs":["typescript","javascript","python"],"tags":["recursion","objects","dfs","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.109Z"},{"id":"6b093dddbd4755deb67ee061","slug":"debounce-throttle","title":"Debounce i throttle","summary":"Dwie klasyczne funkcje wyższego rzędu z frontendu – debounce (wywołaj po ciszy) i throttle (najwyżej raz na okres) – z cancel, flush, zachowaniem this i wstrzykiwanymi timerami.","servedLang":"pl","availableLangs":["pl","en"],"kind":"code","category":"algorithms","status":"published","difficulty":"medium","topics":["decorator"],"techs":["typescript","javascript"],"tags":["javascript","closures","timers","event-loop","higher-order-functions"],"languages":["typescript","javascript"],"questionCount":null,"xp":20,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:53.681Z"},{"id":"6b093dc291bd8fbaf2a0c8dc","slug":"pricing-formula-visitor","title":"Odwiedzający dla formuł cenowych","summary":"Drzewo formuły cenowej i trzy operacje na nim – obliczanie, wypisywanie i upraszczanie – jako odwiedzający. Nowa operacja nie zmienia klas węzłów.","servedLang":"pl","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"hard","topics":["visitor"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["visitor","double-dispatch","expression-tree","composite","behavioral"],"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:26.391Z"},{"id":"6b093dc191bd8fbaf2a0c8d4","slug":"paged-results-iterator","title":"Leniwy iterator po stronicowanym API","summary":"Zamówienia z API zwracającego strony z kursorem jako jedna kolekcja – leniwe pobieranie stron, pomijanie pustych, ochrona przed zapętlonym kursorem i natywny protokół iteracji w każdym języku.","servedLang":"pl","availableLangs":["pl","en"],"kind":"code","category":"pattern","status":"published","difficulty":"medium","topics":["iterator"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["iterator","pagination","lazy-evaluation","generators","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:25.658Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"gof-structural","title":"Wzorce strukturalne GoF","items":[{"slug":"adapter","title":"Adapter – jak dogadać się z kodem, który mówi innym językiem","current":false},{"slug":"bridge","title":"Most (Bridge) – dwie osie zmian bez eksplozji klas","current":false},{"slug":"composite","title":"Kompozyt (Composite) – drzewa, w których liść i gałąź wyglądają tak samo","current":true},{"slug":"decorator","title":"Dekorator (Decorator) – dokładanie zachowania warstwa po warstwie","current":false},{"slug":"facade","title":"Fasada (Facade) – jedno proste wejście do skomplikowanego podsystemu","current":false},{"slug":"flyweight","title":"Pyłek (Flyweight) – jak zmieścić w pamięci 60 tysięcy miejsc na stadionie","current":false},{"slug":"proxy","title":"Pełnomocnik (Proxy) – zastępca, który kontroluje dostęp do prawdziwego obiektu","current":false}]}],"prev":{"slug":"bridge","title":"Most (Bridge) – dwie osie zmian bez eksplozji klas"},"next":{"slug":"decorator","title":"Dekorator (Decorator) – dokładanie zachowania warstwa po warstwie"},"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}]}}