{"id":"6b08bd3480884893657cc96a","slug":"flyweight","title":"Pyłek (Flyweight) – jak zmieścić w pamięci 60 tysięcy miejsc na stadionie","summary":"Pyłek oddziela stan wspólny dla wielu obiektów od stanu unikalnego i współdzieli ten pierwszy. Przykład mapy miejsc stadionu w systemie rezerwacji biletów w C#, TypeScript, Javie, Go i Pythonie.","servedLang":"pl","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":11,"stats":{"views":5,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:56.361Z","updatedAt":"2026-11-27T11:21:15.445Z","requestedLang":"pl","theme":{"hero":"classic","heroMedia":null,"accent":"indigo","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"Wzorzec Pyłek (Flyweight) – stan wewnętrzny i zewnętrzny, fabryka pyłków, szacunek oszczędności pamięci, kod w C#, TypeScript, Java, Go i Python, interning napisów, Integer.valueOf, unique.Make w Go, __slots__ w Pythonie.","wordCount":2076,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Większość wzorców GoF dotyczy czytelności i elastyczności kodu. "},{"type":"text","text":"Pyłek","marks":[{"type":"bold"}]},{"type":"text","text":" (ang. "},{"type":"text","text":"Flyweight","marks":[{"type":"italic"}]},{"type":"text","text":") jest wyjątkiem – to wzorzec optymalizacyjny. Gdy masz setki tysięcy podobnych obiektów, które różnią się tylko kilkoma polami, Pyłek wyciąga wspólną część do jednego współdzielonego egzemplarza, a w każdym obiekcie zostawia tylko to, co naprawdę unikalne."}]},{"type":"callout","attrs":{"variant":"info","title":"W skrócie"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Stan obiektu dzielisz na "},{"type":"text","text":"wewnętrzny","marks":[{"type":"bold"}]},{"type":"text","text":" (wspólny, niezmienny – kategoria, cena, ikona) i "},{"type":"text","text":"zewnętrzny","marks":[{"type":"bold"}]},{"type":"text","text":" (unikalny – rząd, numer)."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Stan wewnętrzny trafia do współdzielonego obiektu-pyłku; fabryka pilnuje, by każdy istniał tylko raz."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Pyłki muszą być niezmienne – inaczej zmiana jednego obiektu zmieni tysiące."}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"problem-mapa-stadionu-ktora-zjada-pamiec"},"content":[{"type":"text","text":"Problem: mapa stadionu, która zjada pamięć"}]},{"type":"paragraph","content":[{"type":"text","text":"System rezerwacji biletów pokazuje interaktywną mapę stadionu: 60 000 miejsc, każde z kategorią (VIP, standard, dla osób z niepełnosprawnościami), ceną, kolorem i ikoną SVG używaną do rysowania. Pierwsza wersja modelu była prosta:"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"seat.ts"},"content":[{"type":"text","text":"class Seat {\n  constructor(\n    public row: number,\n    public number: number,\n    public category: string, // the same 6 values repeated 60 000 times\n    public price: number,\n    public color: string,\n    public iconSvg: string,  // ~2 KB of path data, copied into every seat\n  ) {}\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"Ikona ma około 2 KB danych ścieżek, a powtarza się w każdym z 60 tysięcy miejsc. Serwer, który trzyma mapy kilku wydarzeń naraz w pamięci podręcznej, zaczyna się dławić, a aplikacja w przeglądarce telefonu – przycinać przy przewijaniu."}]},{"type":"chart","attrs":{"type":"bar","title":"Pamięć mapy miejsc: kopie kontra współdzielone typy","caption":"Szacunek ilustracyjny przy założeniu ok. 2 KB danych typu miejsca i 48 B na miejsce z referencją; realne wartości zależą od środowiska uruchomieniowego.","unit":"MB","data":{"labels":["Hala, 5 000 miejsc","Arena, 20 000 miejsc","Stadion, 60 000 miejsc"],"series":[{"name":"Kopie w każdym miejscu","values":[10.4,41.8,125.3]},{"name":"Pyłek","values":[0.25,0.97,2.89]}]}}},{"type":"heading","attrs":{"level":2,"id":"rozwiazanie-wspoldziel-to-co-powtarzalne"},"content":[{"type":"text","text":"Rozwiązanie: współdziel to, co powtarzalne"}]},{"type":"paragraph","content":[{"type":"text","text":"Zauważamy, że na stadionie jest raptem kilka "},{"type":"text","text":"typów","marks":[{"type":"bold"}]},{"type":"text","text":" miejsc, a tysiące "},{"type":"text","text":"miejsc","marks":[{"type":"bold"}]},{"type":"text","text":". Kategoria, cena, kolor i ikona należą do typu – to stan wewnętrzny ("},{"type":"text","text":"intrinsic","marks":[{"type":"italic"}]},{"type":"text","text":"). Rząd i numer należą do konkretnego miejsca – to stan zewnętrzny ("},{"type":"text","text":"extrinsic","marks":[{"type":"italic"}]},{"type":"text","text":"). Wydzielamy niezmienną klasę "},{"type":"text","text":"SeatType","marks":[{"type":"code"}]},{"type":"text","text":", a "},{"type":"text","text":"Seat","marks":[{"type":"code"}]},{"type":"text","text":" przechowuje tylko rząd, numer i referencję do typu. Fabryka "},{"type":"text","text":"SeatTypeFactory","marks":[{"type":"code"}]},{"type":"text","text":" zwraca istniejący typ, zamiast tworzyć nowy."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  direction LR\n  class SeatTypeFactory {\n    -types Map\n    +get(category) SeatType\n  }\n  class SeatType {\n    <<flyweight>>\n    +category\n    +price\n    +color\n    +iconSvg\n  }\n  class Seat {\n    +row\n    +number\n    +type SeatType\n    +describe()\n  }\n  SeatTypeFactory o-- SeatType : buforuje\n  Seat --> SeatType : współdzieli","caption":"Tysiące lekkich miejsc wskazują na kilka współdzielonych typów"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Stan"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Przykład"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Gdzie żyje"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Ile kopii"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Wewnętrzny ("},{"type":"text","text":"intrinsic","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"kategoria, cena, kolor, ikona"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"SeatType","marks":[{"type":"code"}]},{"type":"text","text":" (pyłek)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"po jednej na typ – tu 2"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Zewnętrzny ("},{"type":"text","text":"extrinsic","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"rząd, numer, status rezerwacji"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Seat","marks":[{"type":"code"}]},{"type":"text","text":" (kontekst)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"po jednej na miejsce – 60 000"}]}]}]}]},{"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":"Pyłek ("},{"type":"text","text":"Flyweight","marks":[{"type":"italic"}]},{"type":"text","text":")"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"SeatType","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"niezmienny, współdzielony stan wewnętrzny"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Fabryka pyłków"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"SeatTypeFactory","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"zwraca istniejący egzemplarz albo tworzy go raz"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Kontekst"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Seat","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"stan zewnętrzny + referencja do pyłku"}]}]}]},{"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 mapy"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"tworzy miejsca przez fabrykę, przekazuje stan zewnętrzny"}]}]}]}]},{"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 przykład tworzy 60 000 miejsc, a fabryka zgłasza na koniec, że istnieją tylko dwa typy. W C# "},{"type":"text","text":"Seat","marks":[{"type":"code"}]},{"type":"text","text":" jest strukturą ("},{"type":"text","text":"readonly record struct","marks":[{"type":"code"}]},{"type":"text","text":"), więc same miejsca nie są nawet osobnymi obiektami na stercie; w Pythonie "},{"type":"text","text":"slots=True","marks":[{"type":"code"}]},{"type":"text","text":" usuwa słownik atrybutów z każdej instancji."}]},{"type":"codeGroup","attrs":{"title":"SeatTypeFactory"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"SeatMap.cs"},"content":[{"type":"text","text":"var factory = new SeatTypeFactory();\nvar seats = new List<Seat>(capacity: 60_000);\nfor (var row = 1; row <= 200; row++)\n    for (var number = 1; number <= 300; number++)\n        seats.Add(new Seat(row, number, factory.Get(row <= 20 ? \"VIP\" : \"Standard\")));\n\nConsole.WriteLine($\"{seats.Count} seats, {factory.Count} shared seat types\");\nConsole.WriteLine(seats[0].Describe());\n\n// Flyweight: intrinsic, immutable state shared by thousands of seats.\npublic sealed record SeatType(string Category, decimal Price, string Color, string IconSvg);\n\n// Context: extrinsic state unique to each seat, plus a reference to the flyweight.\npublic readonly record struct Seat(int Row, int Number, SeatType Type)\n{\n    public string Describe() => $\"Row {Row}, seat {Number}: {Type.Category}, {Type.Price} PLN\";\n}\n\n// Flyweight factory: returns an existing instance instead of creating duplicates.\npublic sealed class SeatTypeFactory\n{\n    private readonly Dictionary<string, SeatType> _types = new();\n\n    public int Count => _types.Count;\n\n    public SeatType Get(string category)\n    {\n        if (!_types.TryGetValue(category, out var type))\n        {\n            type = category == \"VIP\"\n                ? new SeatType(\"VIP\", 450m, \"#C9A227\", LoadIcon(\"vip\"))\n                : new SeatType(\"Standard\", 120m, \"#4263EB\", LoadIcon(\"standard\"));\n            _types[category] = type;\n        }\n        return type;\n    }\n\n    private static string LoadIcon(string name) => $\"<svg><!-- {name}: ~2 KB of path data --></svg>\";\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"seat-map.ts"},"content":[{"type":"text","text":"// Flyweight: intrinsic, immutable state shared by thousands of seats.\ninterface SeatType {\n  readonly category: string;\n  readonly price: number;\n  readonly color: string;\n  readonly iconSvg: string;\n}\n\n// Context: extrinsic state unique to each seat, plus a reference to the flyweight.\nclass Seat {\n  constructor(readonly row: number, readonly number: number, readonly type: SeatType) {}\n\n  describe(): string {\n    return `Row ${this.row}, seat ${this.number}: ${this.type.category}, ${this.type.price} PLN`;\n  }\n}\n\n// Flyweight factory: returns an existing instance instead of creating duplicates.\nclass SeatTypeFactory {\n  private readonly types = new Map<string, SeatType>();\n\n  get size(): number {\n    return this.types.size;\n  }\n\n  get(category: \"VIP\" | \"Standard\"): SeatType {\n    let type = this.types.get(category);\n    if (!type) {\n      type = Object.freeze(\n        category === \"VIP\"\n          ? { category, price: 450, color: \"#C9A227\", iconSvg: loadIcon(\"vip\") }\n          : { category, price: 120, color: \"#4263EB\", iconSvg: loadIcon(\"standard\") },\n      );\n      this.types.set(category, type);\n    }\n    return type;\n  }\n}\n\nconst loadIcon = (name: string) => `<svg><!-- ${name}: ~2 KB of path data --></svg>`;\n\nconst factory = new SeatTypeFactory();\nconst seats: Seat[] = [];\nfor (let row = 1; row <= 200; row++) {\n  for (let n = 1; n <= 300; n++) seats.push(new Seat(row, n, factory.get(row <= 20 ? \"VIP\" : \"Standard\")));\n}\nconsole.log(`${seats.length} seats, ${factory.size} shared seat types`);\nconsole.log(seats[0].describe());"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"SeatMap.java"},"content":[{"type":"text","text":"import java.math.BigDecimal;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\n// Flyweight: intrinsic, immutable state shared by thousands of seats.\nrecord SeatType(String category, BigDecimal price, String color, String iconSvg) {}\n\n// Context: extrinsic state unique to each seat, plus a reference to the flyweight.\nrecord Seat(int row, int number, SeatType type) {\n    String describe() {\n        return \"Row \" + row + \", seat \" + number + \": \" + type.category() + \", \" + type.price() + \" PLN\";\n    }\n}\n\n// Flyweight factory: returns an existing instance instead of creating duplicates.\nfinal class SeatTypeFactory {\n    private final Map<String, SeatType> types = new HashMap<>();\n\n    SeatType get(String category) {\n        return types.computeIfAbsent(category, c -> c.equals(\"VIP\")\n            ? new SeatType(\"VIP\", new BigDecimal(\"450\"), \"#C9A227\", loadIcon(\"vip\"))\n            : new SeatType(\"Standard\", new BigDecimal(\"120\"), \"#4263EB\", loadIcon(\"standard\")));\n    }\n\n    int count() { return types.size(); }\n\n    private static String loadIcon(String name) { return \"<svg><!-- \" + name + \": ~2 KB of path data --></svg>\"; }\n}\n\npublic class SeatMap {\n    public static void main(String[] args) {\n        var factory = new SeatTypeFactory();\n        List<Seat> seats = new ArrayList<>(60_000);\n        for (int row = 1; row <= 200; row++)\n            for (int number = 1; number <= 300; number++)\n                seats.add(new Seat(row, number, factory.get(row <= 20 ? \"VIP\" : \"Standard\")));\n\n        System.out.println(seats.size() + \" seats, \" + factory.count() + \" shared seat types\");\n        System.out.println(seats.get(0).describe());\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"seatmap.go"},"content":[{"type":"text","text":"package main\n\nimport \"fmt\"\n\n// SeatType is the flyweight: intrinsic, immutable state shared by thousands of seats.\ntype SeatType struct {\n\tCategory string\n\tPrice    int\n\tColor    string\n\tIconSVG  string\n}\n\n// Seat is the context: small extrinsic state plus a pointer to the shared flyweight.\ntype Seat struct {\n\tRow, Number int32\n\tType        *SeatType\n}\n\n// SeatTypeFactory returns an existing instance instead of creating duplicates.\ntype SeatTypeFactory struct{ types map[string]*SeatType }\n\nfunc NewSeatTypeFactory() *SeatTypeFactory {\n\treturn &SeatTypeFactory{types: make(map[string]*SeatType)}\n}\n\nfunc (f *SeatTypeFactory) Get(category string) *SeatType {\n\tif t, ok := f.types[category]; ok {\n\t\treturn t\n\t}\n\tt := &SeatType{Category: \"Standard\", Price: 120, Color: \"#4263EB\", IconSVG: loadIcon(\"standard\")}\n\tif category == \"VIP\" {\n\t\tt = &SeatType{Category: \"VIP\", Price: 450, Color: \"#C9A227\", IconSVG: loadIcon(\"vip\")}\n\t}\n\tf.types[category] = t\n\treturn t\n}\n\nfunc loadIcon(name string) string { return \"<svg><!-- \" + name + \": ~2 KB of path data --></svg>\" }\n\nfunc main() {\n\tfactory := NewSeatTypeFactory()\n\tseats := make([]Seat, 0, 60_000)\n\tfor row := int32(1); row <= 200; row++ {\n\t\tfor n := int32(1); n <= 300; n++ {\n\t\t\tcategory := \"Standard\"\n\t\t\tif row <= 20 {\n\t\t\t\tcategory = \"VIP\"\n\t\t\t}\n\t\t\tseats = append(seats, Seat{Row: row, Number: n, Type: factory.Get(category)})\n\t\t}\n\t}\n\tfmt.Println(len(seats), \"seats,\", len(factory.types), \"shared seat types\")\n\ts := seats[0]\n\tfmt.Printf(\"Row %d, seat %d: %s, %d PLN\\n\", s.Row, s.Number, s.Type.Category, s.Type.Price)\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"seat_map.py"},"content":[{"type":"text","text":"from dataclasses import dataclass\n\n\n@dataclass(frozen=True, slots=True)\nclass SeatType:\n    \"\"\"Flyweight: intrinsic, immutable state shared by thousands of seats.\"\"\"\n\n    category: str\n    price: int\n    color: str\n    icon_svg: str\n\n\n@dataclass(frozen=True, slots=True)\nclass Seat:\n    \"\"\"Context: extrinsic state unique to each seat, plus a reference to the flyweight.\"\"\"\n\n    row: int\n    number: int\n    type: SeatType\n\n    def describe(self) -> str:\n        return f\"Row {self.row}, seat {self.number}: {self.type.category}, {self.type.price} PLN\"\n\n\nclass SeatTypeFactory:\n    \"\"\"Returns an existing instance instead of creating duplicates.\"\"\"\n\n    def __init__(self) -> None:\n        self._types: dict[str, SeatType] = {}\n\n    def get(self, category: str) -> SeatType:\n        if category not in self._types:\n            if category == \"VIP\":\n                self._types[category] = SeatType(\"VIP\", 450, \"#C9A227\", load_icon(\"vip\"))\n            else:\n                self._types[category] = SeatType(\"Standard\", 120, \"#4263EB\", load_icon(\"standard\"))\n        return self._types[category]\n\n    def __len__(self) -> int:\n        return len(self._types)\n\n\ndef load_icon(name: str) -> str:\n    return f\"<svg><!-- {name}: ~2 KB of path data --></svg>\"\n\n\nif __name__ == \"__main__\":\n    factory = SeatTypeFactory()\n    seats = [\n        Seat(row, number, factory.get(\"VIP\" if row <= 20 else \"Standard\"))\n        for row in range(1, 201)\n        for number in range(1, 301)\n    ]\n    print(f\"{len(seats)} seats, {len(factory)} shared seat types\")\n    print(seats[0].describe())"}]}]}]},"toc":[{"id":"problem-mapa-stadionu-ktora-zjada-pamiec","text":"Problem: mapa stadionu, która zjada pamięć","level":2,"locked":false},{"id":"rozwiazanie-wspoldziel-to-co-powtarzalne","text":"Rozwiązanie: współdziel to, co powtarzalne","level":2,"locked":false},{"id":"implementacja-w-pieciu-jezykach","text":"Implementacja w pięciu językach","level":2,"locked":false},{"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":"6b0857bf3c96f2d34d0b4272","type":"article","provider":"web","url":"https://gameprogrammingpatterns.com/flyweight.html","embedUrl":null,"title":"Flyweight · Design Patterns Revisited · Game Programming Patterns","description":"","author":"Robert Nystrom","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["flyweight"],"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.321Z"},{"id":"6b0857bf3c96f2d34d0b4271","type":"article","provider":"web","url":"https://refactoring.guru/design-patterns/flyweight","embedUrl":null,"title":"Flyweight","description":"Flyweight is a structural design pattern that lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"en","topics":["flyweight"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":65,"verifiedAt":"2026-11-26T11:26:03.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857b23c96f2d34d0b35b8","type":"repo","provider":"github","url":"https://github.com/Habrador/Unity-Programming-Patterns","embedUrl":null,"title":"Habrador/Unity-Programming-Patterns","description":"Implementations of programming design patterns in Unity with examples in C# when to use them.","author":"Habrador","thumbnailUrl":"https://opengraph.githubassets.com/1/Habrador/Unity-Programming-Patterns","durationSec":null,"lang":"en","topics":["prototype","singleton","flyweight","command","observer"],"techs":["dotnet"],"tags":["architecture","command-pattern","computer-science","design-patterns","factory-pattern","flyweight-pattern","software-architecture","game-programming-pattern","object-pool","object-pool-pattern"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2020-06-14T12:53:46.000Z","popularity":64,"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":"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":"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":"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":"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":"6b0857af5a2625e44ecaad0a","slug":"notification-factory","title":"Fabryka powiadomień","summary":"Zaimplementuj Metodę wytwórczą: każdy serwis powiadomień sam decyduje, jaki kanał (e-mail, SMS, push) tworzy.","servedLang":"pl","availableLangs":["pl","en"],"kind":"code","category":null,"status":"published","difficulty":"easy","topics":["factory-method"],"techs":["typescript","javascript"],"tags":["factory-method","notifications","creational"],"languages":["typescript","javascript"],"questionCount":null,"xp":10,"stats":{"attempts":1,"solves":1,"solutions":1,"comments":0},"solveRate":100,"publishedAt":"2026-11-26T16:00:47.675Z"}],"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":false},{"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":true},{"slug":"proxy","title":"Pełnomocnik (Proxy) – zastępca, który kontroluje dostęp do prawdziwego obiektu","current":false}]}],"prev":{"slug":"facade","title":"Fasada (Facade) – jedno proste wejście do skomplikowanego podsystemu"},"next":{"slug":"proxy","title":"Pełnomocnik (Proxy) – zastępca, który kontroluje dostęp do prawdziwego obiektu"},"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}]}}