{"id":"6b08bd3180884893657cc91a","slug":"composite","title":"Composite – trees in which a leaf and a branch look the same","summary":"Composite lets you treat a single object and a whole group of objects in exactly the same way. A course curriculum example with modules and lessons in C#, TypeScript, Java, Go and Python.","servedLang":"en","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":11,"stats":{"views":3,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:53.346Z","updatedAt":"2026-11-27T13:05:54.209Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"indigo","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"The Composite design pattern – tree structures, component, leaf and composite, transparency versus safety, diagrams, code in C#, TypeScript, Java, Go and Python, examples from Swing, io.MultiWriter, unittest and the DOM.","wordCount":2068,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Menus with submenus, folders with files, a company department with teams, a course with modules and lessons – trees are everywhere. "},{"type":"text","text":"Composite","marks":[{"type":"bold"}]},{"type":"text","text":" means code working with a tree does not have to ask \"is this a leaf or a branch?\": both have the same interface, and a branch simply passes the call on to its children."}]},{"type":"callout","attrs":{"variant":"info","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A leaf (a lesson) and a composite (a section) implement a common component interface."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The composite stores children of the component type and aggregates their results – recursion does the rest."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The client calls "},{"type":"text","text":"minutes()","marks":[{"type":"code"}]},{"type":"text","text":" on a whole course exactly as it would on a single lesson."}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"the-problem-how-long-is-this-course"},"content":[{"type":"text","text":"The problem: how long is this course?"}]},{"type":"paragraph","content":[{"type":"text","text":"A programming course platform shows the total video length next to each course. A course consists of lessons and sections, and sections may contain further sections – authors love \"bonuses within bonuses\". The first implementation:"}]},{"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":"The same "},{"type":"text","text":"instanceof","marks":[{"type":"code"}]},{"type":"text","text":" ladder shows up in printing the table of contents, counting lessons, exporting to PDF and tracking progress. Every new node type – a quiz, a live session – requires fixes in all those places."}]},{"type":"heading","attrs":{"level":2,"id":"the-solution-a-common-interface-for-leaf-and-branch"},"content":[{"type":"text","text":"The solution: a common interface for leaf and branch"}]},{"type":"paragraph","content":[{"type":"text","text":"We define a "},{"type":"text","text":"CurriculumItem","marks":[{"type":"code"}]},{"type":"text","text":" interface with operations that make sense for every node: "},{"type":"text","text":"minutes()","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"print()","marks":[{"type":"code"}]},{"type":"text","text":". "},{"type":"text","text":"Lesson","marks":[{"type":"code"}]},{"type":"text","text":" (the leaf) is responsible for itself. "},{"type":"text","text":"Section","marks":[{"type":"code"}]},{"type":"text","text":" (the composite) holds a list of "},{"type":"text","text":"CurriculumItem","marks":[{"type":"code"}]},{"type":"text","text":" children and implements the same methods by delegating to the children and summing the results. The client cannot tell one from the other."}]},{"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 : children","caption":"Composite structure"}},{"type":"paragraph","content":[{"type":"text","text":"This is the tree from our example. The time of each section is the sum of its children's times – computed recursively, without a single "},{"type":"text","text":"instanceof","marks":[{"type":"code"}]},{"type":"text","text":":"}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"flowchart TD\n  C[\"Course: 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":"The example course as a tree – sections sum their children's time"}},{"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":"Component"}]}]},{"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":"the common interface of leaves and composites"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Leaf"}]}]},{"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":"does the actual work, has no children"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Composite"}]}]},{"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":"stores children, delegates to them and aggregates results"}]}]}]},{"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 course view"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"works with components without knowing their kind"}]}]}]}]},{"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 Java the interface is "},{"type":"text","text":"sealed","marks":[{"type":"code"}]},{"type":"text","text":" – the compiler knows every kind of node, which helps with pattern matching in "},{"type":"text","text":"switch","marks":[{"type":"code"}]},{"type":"text","text":". In Go the leaf and the composite are ordinary structs satisfying the same interface, and in Python a "},{"type":"text","text":"Protocol","marks":[{"type":"code"}]},{"type":"text","text":" is enough."}]},{"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":"the-problem-how-long-is-this-course","text":"The problem: how long is this course?","level":2,"locked":false},{"id":"the-solution-a-common-interface-for-leaf-and-branch","text":"The solution: a common interface for leaf and branch","level":2,"locked":false},{"id":"implementation-in-five-languages","text":"Implementation in five languages","level":2,"locked":false},{"id":"transparency-or-safety","text":"Transparency or safety?","level":2,"locked":true},{"id":"step-by-step","text":"Step by step","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":"quick-check","text":"Quick check","level":2,"locked":true},{"id":"summary","text":"Summary","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":"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"},{"id":"6b093ddebd4755deb67ee06e","slug":"flatten-object","title":"Flatten a nested object","summary":"Turn a nested JSON object into a flat path → value map (e.g. for a CSV export or a config diff). Recursion or an explicit stack, leaves and empty containers.","servedLang":"en","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 and throttle","summary":"Two classic frontend higher-order functions – debounce (call after silence) and throttle (at most once per period) – with cancel, flush, preserved this and injected timers.","servedLang":"en","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":"Pricing formula visitor","summary":"A pricing formula tree and three operations on it – evaluation, printing and simplification – as visitors. A new operation leaves the node classes untouched.","servedLang":"en","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":"Lazy iterator over a paged API","summary":"Orders from an API that returns pages with a cursor, exposed as one collection – lazy page fetching, skipping empty pages, protection against a looping cursor and the native iteration protocol of every language.","servedLang":"en","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":"GoF structural patterns","items":[{"slug":"adapter","title":"Adapter – how to get along with code that speaks another language","current":false},{"slug":"bridge","title":"Bridge – two axes of change without a class explosion","current":false},{"slug":"composite","title":"Composite – trees in which a leaf and a branch look the same","current":true},{"slug":"decorator","title":"Decorator – adding behaviour layer by layer","current":false},{"slug":"facade","title":"Facade – one simple entry point to a complex subsystem","current":false},{"slug":"flyweight","title":"Flyweight – how to fit 60,000 stadium seats in memory","current":false},{"slug":"proxy","title":"Proxy – a stand-in that controls access to the real object","current":false}]}],"prev":{"slug":"bridge","title":"Bridge – two axes of change without a class explosion"},"next":{"slug":"decorator","title":"Decorator – adding behaviour layer by layer"},"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}]}}