Umožní pracovať so stromom objektov rovnako ako s jediným objektom.
class Item { size() { throw new Error('abstraktná metóda'); }} class File extends Item { constructor(bytes) { super(); this.bytes = bytes; } size() { return this.bytes; }} class Folder extends Item { children = []; add(item) { this.children.push(item); } size() { let total = 0; for (const child of this.children) { total += child.size(); } return total; }} const album = new Folder();album.add(new File(900)); const root = new Folder();root.add(new File(120));root.add(album); root.size(); // 1020 — the client never asked what is inside