{"slug":"composite","group":"structural","title":"Composite","short":"Lets clients treat a single element and a whole tree of elements in exactly the same way.","icon":"network","aliases":[],"order":203,"status":"available","articleCount":5,"groupTitle":"Structural patterns","intro":"","servedLang":"en","primaryArticle":{"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","challengeCount":1,"quizCount":1},"articles":[{"id":"6b093dc091bd8fbaf2a0c8b2","slug":"specification","title":"Specification: business rules as objects you can combine","summary":"The Specification pattern from Domain-Driven Design: named rules with isSatisfiedBy, combining with and, or and not, one rule for validation and querying, translation to SQL via expression trees, the Criteria API and Q objects. Code in C#, TypeScript, Java, Go and Python.","servedLang":"en","availableLangs":["pl","en"],"topics":["specification","composite","ddd-strategic-design"],"techs":["dotnet","typescript","java","go","python"],"tags":["ddd","specification","business-rules","repository","expression-trees","tactical-patterns"],"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":1,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T08:22:24.343Z","updatedAt":"2026-11-27T10:04:40.031Z","relation":{"position":1,"primary":false,"mainTopic":{"slug":"specification","title":"Specification"}}},{"id":"6b08bd3480884893657cc96a","slug":"flyweight","title":"Flyweight – how to fit 60,000 stadium seats in memory","summary":"Flyweight separates the state shared by many objects from the state unique to each one, and shares the former. A stadium seat map example from a ticket booking system in C#, TypeScript, Java, Go and Python.","servedLang":"en","availableLangs":["pl","en"],"topics":["flyweight","composite","singleton","factory-method"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","structural","flyweight","memory","performance","interning"],"level":"advanced","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":6,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:56.361Z","updatedAt":"2026-11-27T13:06:02.992Z","relation":{"position":1,"primary":false,"mainTopic":{"slug":"flyweight","title":"Flyweight"}}},{"id":"6b08bd2f80884893657cc8f2","slug":"builder","title":"Builder – complex objects step by step","summary":"Builder collects an object's parameters in readable steps and hands over a finished, valid product only in build(). A catering order example in C#, TypeScript, Java, Go and Python.","servedLang":"en","availableLangs":["pl","en"],"topics":["builder","abstract-factory","composite"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","creational","builder","fluent-interface","immutability"],"level":"beginner","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:51.940Z","updatedAt":"2026-11-27T13:04:58.174Z","relation":{"position":2,"primary":false,"mainTopic":{"slug":"builder","title":"Builder"}}},{"id":"6b08bd3280884893657cc938","slug":"decorator","title":"Decorator – adding behaviour layer by layer","summary":"Decorator wraps an object in another object with the same interface and adds behaviour before or after the call. An example of caching, retries and logging for an exchange rate provider in C#, TypeScript, Java, Go and Python.","servedLang":"en","availableLangs":["pl","en"],"topics":["decorator","proxy","chain-of-responsibility","composite"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","structural","decorator","middleware","cross-cutting-concerns"],"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:54.428Z","updatedAt":"2026-11-27T13:08:21.545Z","relation":{"position":3,"primary":false,"mainTopic":{"slug":"decorator","title":"Decorator"}}}],"challenges":[{"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":"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"}],"resources":[{"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":"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":"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"},{"id":"6b0857bf3c96f2d34d0b427a","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/composite","embedUrl":null,"title":"Kompozyt / Composite","description":"Kompozyt to strukturalny wzorzec projektowy pozwalający komponować obiekty w struktury drzewiaste, a następnie traktować te struktury jakby były osobnymi obiektami.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["composite"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":65,"verifiedAt":"2026-11-26T11:26:10.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"}],"resourceGroups":[{"type":"video","items":[{"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"}]},{"type":"article","items":[{"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":"6b0857bf3c96f2d34d0b427a","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/composite","embedUrl":null,"title":"Kompozyt / Composite","description":"Kompozyt to strukturalny wzorzec projektowy pozwalający komponować obiekty w struktury drzewiaste, a następnie traktować te struktury jakby były osobnymi obiektami.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["composite"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":65,"verifiedAt":"2026-11-26T11:26:10.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"}]},{"type":"book","items":[{"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"}]},{"type":"repo","items":[{"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"}]}],"siblings":[{"slug":"adapter","title":"Adapter","icon":"plug","status":"available","current":false},{"slug":"bridge","title":"Bridge","icon":"spline","status":"available","current":false},{"slug":"composite","title":"Composite","icon":"network","status":"available","current":true},{"slug":"decorator","title":"Decorator","icon":"layers","status":"available","current":false},{"slug":"facade","title":"Facade","icon":"building","status":"available","current":false},{"slug":"flyweight","title":"Flyweight","icon":"feather","status":"available","current":false},{"slug":"proxy","title":"Proxy","icon":"shield","status":"available","current":false}]}