{"id":"6b08bd3e80884893657cca24","slug":"template-method","title":"Template Method: a fixed recipe, interchangeable ingredients","summary":"The Template Method pattern through importing supplier price lists: the base class fixes the order of steps, and subclasses provide parsing and optional hooks. The Hollywood principle, an inheritance-free variant in Go and code in five languages.","servedLang":"en","availableLangs":["pl","en"],"topics":["template-method"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","behavioral","template-method","inheritance","hooks"],"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":13,"stats":{"views":3,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:14:06.512Z","updatedAt":"2026-11-27T13:17:19.349Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"violet","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"The Template Method design pattern in C#, TypeScript, Java, Go and Python: an algorithm skeleton, abstract steps, hooks, and a comparison with Strategy.","wordCount":2538,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Every kind of Halina's pierogi follows the same recipe: dough, filling, folding, boiling, sometimes frying afterwards. The filling changes; the order never does. "},{"type":"text","text":"Template Method","marks":[{"type":"bold"}]},{"type":"text","text":" writes such a recipe down in a base class and leaves subclasses only the steps that really differ. In the pierogi place's code, that recipe is importing price lists from suppliers."}]},{"type":"callout","attrs":{"variant":"tip","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The base class defines a "},{"type":"text","text":"template method","marks":[{"type":"bold"}]},{"type":"text","text":" – a fixed sequence of algorithm steps."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Subclasses implement "},{"type":"text","text":"abstract steps","marks":[{"type":"bold"}]},{"type":"text","text":" (required) and may override "},{"type":"text","text":"hooks","marks":[{"type":"bold"}]},{"type":"text","text":" with a default behaviour."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Control is inverted: the base class calls the subclass, not the other way round (\"don't call us, we'll call you\")."}]}]}]}]},{"type":"stats","attrs":{"items":[{"value":"1","label":"method fixes the order","hint":"run() – shared by all imports"},{"value":"1","label":"required step","hint":"parse() – every supplier has a different format"},{"value":"1","label":"optional hook","hint":"adjust() – e.g. a cooling fee"}]}},{"type":"heading","attrs":{"level":2,"id":"the-problem-two-imports-one-logic-two-copies"},"content":[{"type":"text","text":"The problem: two imports, one logic, two copies"}]},{"type":"paragraph","content":[{"type":"text","text":"The farm sends prices as CSV, the dairy as JSON. The first versions of the imports were written by copy and tweak:"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"imports_before.py"},"content":[{"type":"text","text":"def import_farm_csv(raw: str) -> int:\n    items = [line.split(\";\") for line in raw.splitlines() if line]\n    valid = [i for i in items if i[0] and float(i[2].replace(\",\", \".\")) > 0]\n    db.save_prices(valid)\n    return len(valid)\n\n\ndef import_dairy_json(raw: str) -> int:\n    items = json.loads(raw)\n    valid = [i for i in items if i[\"name\"]]  # someone forgot the price check here\n    for i in valid:\n        i[\"price\"] = round(i[\"price\"] * 1.02, 2)  # cooling fee\n    db.save_prices(valid)\n    return len(valid)"}]},{"type":"paragraph","content":[{"type":"text","text":"Both functions do the same thing: parse, validate, adjust and save. Only the first step and the dairy's fee differ. The copied validation has already drifted – in the dairy import someone lost the price check, so cheese for 0 PLN would end up in the database. A third supplier would mean a third copy and a third place to forget a rule."}]},{"type":"heading","attrs":{"level":2,"id":"the-solution-a-skeleton-in-the-base-class"},"content":[{"type":"text","text":"The solution: a skeleton in the base class"}]},{"type":"paragraph","content":[{"type":"text","text":"The shared flow moves to the base class as the "},{"type":"text","text":"run()","marks":[{"type":"code"}]},{"type":"text","text":" method. It calls the steps in order: "},{"type":"text","text":"parse()","marks":[{"type":"code"}]},{"type":"text","text":" is abstract, so every subclass has to provide it; "},{"type":"text","text":"isValid()","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"save()","marks":[{"type":"code"}]},{"type":"text","text":" are private and shared; "},{"type":"text","text":"adjust()","marks":[{"type":"code"}]},{"type":"text","text":" is a "},{"type":"text","text":"hook","marks":[{"type":"bold"}]},{"type":"text","text":" – it has a default \"change nothing\" implementation, but a subclass may override it."}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant C as Client\n  participant B as PriceListImport (base)\n  participant D as DairyJsonImport (subclass)\n  C->>B: run(raw)\n  B->>D: parse(raw)\n  D-->>B: list of items\n  B->>B: isValid() – shared validation\n  B->>D: adjust(item) – hook\n  D-->>B: price + 2%\n  B->>B: save(valid)\n  B-->>C: report: 1 imported, 0 rejected","caption":"Who calls whom: the Hollywood principle"}},{"type":"diagram","attrs":{"kind":"mermaid","code":"classDiagram\n  class PriceListImport {\n    <<abstract>>\n    +run(raw) ImportReport\n    #parse(raw) List~PriceItem~*\n    #adjust(item) PriceItem\n    -isValid(item) bool\n    -save(items)\n  }\n  PriceListImport <|-- FarmCsvImport\n  PriceListImport <|-- DairyJsonImport\n  class FarmCsvImport {\n    #parse(raw) List~PriceItem~\n  }\n  class DairyJsonImport {\n    #parse(raw) List~PriceItem~\n    #adjust(item) PriceItem\n  }","caption":"The structure of the Template Method pattern"}},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Element"}]}]},{"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":"Who defines it"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Template method"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"run()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the base class; not overridable ("},{"type":"text","text":"final","marks":[{"type":"code"}]},{"type":"text","text":", non-virtual)"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Abstract step"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"parse()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"every subclass, mandatory"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Hook"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"adjust()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the base class (default), a subclass optionally"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Shared step"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"isValid()","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"save()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"the base class, privately"}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"implementation-in-five-languages"},"content":[{"type":"text","text":"Implementation in five languages"}]},{"type":"paragraph","content":[{"type":"text","text":"C#, TypeScript, Java and Python implement the pattern classically – with an abstract class. In Java the template method is "},{"type":"text","text":"final","marks":[{"type":"code"}]},{"type":"text","text":"; in C# it is simply not virtual. Go has no inheritance, so the skeleton is a "},{"type":"text","text":"function","marks":[{"type":"bold"}]},{"type":"text","text":" taking an interface with the required step, and the hook is detected with a type assertion: if the parser also implements "},{"type":"text","text":"Adjuster","marks":[{"type":"code"}]},{"type":"text","text":", the function uses it."}]},{"type":"codeGroup","attrs":{"title":"Template Method – price list import"},"content":[{"type":"codeBlock","attrs":{"language":"csharp","filename":"PriceListImport.cs"},"content":[{"type":"text","text":"using System.Globalization;\nusing System.Text.Json;\n\nConsole.WriteLine(new FarmCsvImport().Run(\"cheese;kg;24,50\\npotatoes;kg;3,20\\nonions;kg;-1\"));\nConsole.WriteLine(new DairyJsonImport().Run(\"\"\"[{\"name\":\"cream\",\"unit\":\"l\",\"price\":12.0}]\"\"\"));\n\npublic sealed record PriceItem(string Name, string Unit, decimal Price);\npublic sealed record ImportReport(int Imported, int Rejected);\n\npublic abstract class PriceListImport\n{\n    // The template method: a fixed sequence of steps, deliberately not virtual.\n    public ImportReport Run(string raw)\n    {\n        var items = Parse(raw).ToList();\n        var valid = items.Where(IsValid).Select(Adjust).ToList();\n        Save(valid);\n        return new ImportReport(valid.Count, items.Count - valid.Count);\n    }\n\n    protected abstract IEnumerable<PriceItem> Parse(string raw); // required step\n\n    protected virtual PriceItem Adjust(PriceItem item) => item; // optional hook\n\n    private static bool IsValid(PriceItem i) => i.Name.Length > 0 && i.Price > 0;\n\n    private void Save(List<PriceItem> items) =>\n        items.ForEach(i => Console.WriteLine($\"{GetType().Name}: {i.Name} = {i.Price:0.00} PLN/{i.Unit}\"));\n}\n\npublic sealed class FarmCsvImport : PriceListImport\n{\n    protected override IEnumerable<PriceItem> Parse(string raw) =>\n        raw.Split('\\n', StringSplitOptions.RemoveEmptyEntries)\n           .Select(line => line.Split(';'))\n           .Select(c => new PriceItem(c[0], c[1], decimal.Parse(c[2].Replace(',', '.'), CultureInfo.InvariantCulture)));\n}\n\npublic sealed class DairyJsonImport : PriceListImport\n{\n    private static readonly JsonSerializerOptions Options = new(JsonSerializerDefaults.Web);\n\n    protected override IEnumerable<PriceItem> Parse(string raw) =>\n        JsonSerializer.Deserialize<List<PriceItem>>(raw, Options) ?? [];\n\n    // The dairy adds a 2% cooling fee to every price.\n    protected override PriceItem Adjust(PriceItem item) => item with { Price = Math.Round(item.Price * 1.02m, 2) };\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"price-list-import.ts"},"content":[{"type":"text","text":"type PriceItem = { name: string; unit: string; price: number };\ntype ImportReport = { imported: number; rejected: number };\n\nabstract class PriceListImport {\n  // The template method: subclasses fill in steps but never change their order.\n  run(raw: string): ImportReport {\n    const items = this.parse(raw);\n    const valid = items.filter((i) => this.isValid(i)).map((i) => this.adjust(i));\n    this.save(valid);\n    return { imported: valid.length, rejected: items.length - valid.length };\n  }\n\n  protected abstract parse(raw: string): PriceItem[]; // required step\n\n  protected adjust(item: PriceItem): PriceItem { return item; } // optional hook\n\n  private isValid(i: PriceItem): boolean { return i.name.length > 0 && i.price > 0; }\n\n  private save(items: PriceItem[]): void {\n    for (const i of items) console.log(`${this.constructor.name}: ${i.name} = ${i.price.toFixed(2)} PLN/${i.unit}`);\n  }\n}\n\nclass FarmCsvImport extends PriceListImport {\n  protected parse(raw: string): PriceItem[] {\n    return raw.split('\\n').filter(Boolean).map((line) => {\n      const [name, unit, price] = line.split(';');\n      return { name, unit, price: Number(price.replace(',', '.')) };\n    });\n  }\n}\n\nclass DairyJsonImport extends PriceListImport {\n  protected parse(raw: string): PriceItem[] {\n    return JSON.parse(raw) as PriceItem[];\n  }\n\n  // The dairy adds a 2% cooling fee to every price.\n  protected override adjust(item: PriceItem): PriceItem {\n    return { ...item, price: Math.round(item.price * 102) / 100 };\n  }\n}\n\nconsole.log(new FarmCsvImport().run('cheese;kg;24,50\\npotatoes;kg;3,20\\nonions;kg;-1')); // imported 2, rejected 1\nconsole.log(new DairyJsonImport().run('[{\"name\":\"cream\",\"unit\":\"l\",\"price\":12}]'));      // cream = 12.24"}]},{"type":"codeBlock","attrs":{"language":"java","filename":"PriceListImport.java"},"content":[{"type":"text","text":"import java.util.Arrays;\nimport java.util.List;\nimport java.util.regex.Pattern;\n\nrecord PriceItem(String name, String unit, double price) {}\nrecord ImportReport(int imported, int rejected) {}\n\npublic abstract class PriceListImport {\n    // The template method: final, so subclasses cannot change the order of steps.\n    public final ImportReport run(String raw) {\n        List<PriceItem> items = parse(raw);\n        List<PriceItem> valid = items.stream().filter(this::isValid).map(this::adjust).toList();\n        save(valid);\n        return new ImportReport(valid.size(), items.size() - valid.size());\n    }\n\n    protected abstract List<PriceItem> parse(String raw); // required step\n\n    protected PriceItem adjust(PriceItem item) { return item; } // optional hook\n\n    private boolean isValid(PriceItem i) { return !i.name().isBlank() && i.price() > 0; }\n\n    private void save(List<PriceItem> items) {\n        items.forEach(i -> System.out.printf(\"%s: %s = %.2f PLN/%s%n\", getClass().getSimpleName(), i.name(), i.price(), i.unit()));\n    }\n\n    public static void main(String[] args) {\n        System.out.println(new FarmCsvImport().run(\"cheese;kg;24,50\\npotatoes;kg;3,20\\nonions;kg;-1\"));\n        System.out.println(new DairyLineImport().run(\"cream|l|12.00\"));\n    }\n}\n\nclass FarmCsvImport extends PriceListImport {\n    @Override protected List<PriceItem> parse(String raw) {\n        return raw.lines().filter(l -> !l.isBlank()).map(l -> l.split(\";\"))\n            .map(c -> new PriceItem(c[0], c[1], Double.parseDouble(c[2].replace(',', '.')))).toList();\n    }\n}\n\nclass DairyLineImport extends PriceListImport {\n    private static final Pattern SEP = Pattern.compile(\"\\\\|\");\n\n    @Override protected List<PriceItem> parse(String raw) {\n        return raw.lines().map(SEP::split).map(c -> new PriceItem(c[0], c[1], Double.parseDouble(c[2]))).toList();\n    }\n\n    // The dairy adds a 2% cooling fee to every price.\n    @Override protected PriceItem adjust(PriceItem i) {\n        return new PriceItem(i.name(), i.unit(), Math.round(i.price() * 102) / 100.0);\n    }\n}"}]},{"type":"codeBlock","attrs":{"language":"go","filename":"import.go"},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"math\"\n\t\"strconv\"\n\t\"strings\"\n)\n\ntype PriceItem struct {\n\tName  string  `json:\"name\"`\n\tUnit  string  `json:\"unit\"`\n\tPrice float64 `json:\"price\"`\n}\n\n// Parser is the required step; Adjuster is an optional hook detected at runtime.\ntype Parser interface{ Parse(raw string) ([]PriceItem, error) }\ntype Adjuster interface{ Adjust(PriceItem) PriceItem }\n\n// Run is the template: Go has no inheritance, so the skeleton is a function over an interface.\nfunc Run(p Parser, raw string) (imported, rejected int, err error) {\n\titems, err := p.Parse(raw)\n\tif err != nil {\n\t\treturn 0, 0, err\n\t}\n\tfor _, it := range items {\n\t\tif it.Name == \"\" || it.Price <= 0 {\n\t\t\trejected++\n\t\t\tcontinue\n\t\t}\n\t\tif a, ok := p.(Adjuster); ok {\n\t\t\tit = a.Adjust(it)\n\t\t}\n\t\tfmt.Printf(\"%T: %s = %.2f PLN/%s\\n\", p, it.Name, it.Price, it.Unit) // save\n\t\timported++\n\t}\n\treturn imported, rejected, nil\n}\n\ntype FarmCSV struct{}\n\nfunc (FarmCSV) Parse(raw string) ([]PriceItem, error) {\n\tvar out []PriceItem\n\tfor _, line := range strings.Fields(raw) {\n\t\tc := strings.Split(line, \";\")\n\t\tprice, err := strconv.ParseFloat(strings.Replace(c[2], \",\", \".\", 1), 64)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tout = append(out, PriceItem{c[0], c[1], price})\n\t}\n\treturn out, nil\n}\n\ntype DairyJSON struct{}\n\nfunc (DairyJSON) Parse(raw string) (items []PriceItem, err error) {\n\terr = json.Unmarshal([]byte(raw), &items)\n\treturn items, err\n}\n\n// Adjust adds the dairy's 2% cooling fee.\nfunc (DairyJSON) Adjust(i PriceItem) PriceItem {\n\ti.Price = math.Round(i.Price*102) / 100\n\treturn i\n}\n\nfunc main() {\n\tfmt.Println(Run(FarmCSV{}, \"cheese;kg;24,50\\npotatoes;kg;3,20\\nonions;kg;-1\"))\n\tfmt.Println(Run(DairyJSON{}, `[{\"name\":\"cream\",\"unit\":\"l\",\"price\":12}]`))\n}"}]},{"type":"codeBlock","attrs":{"language":"python","filename":"price_list_import.py"},"content":[{"type":"text","text":"import json\nfrom abc import ABC, abstractmethod\nfrom dataclasses import dataclass, replace\n\n\n@dataclass(frozen=True)\nclass PriceItem:\n    name: str\n    unit: str\n    price: float\n\n\nclass PriceListImport(ABC):\n    def run(self, raw: str) -> tuple[int, int]:\n        \"\"\"The template method: subclasses fill in steps, never the order.\"\"\"\n        items = self.parse(raw)\n        valid = [self.adjust(i) for i in items if self._is_valid(i)]\n        self._save(valid)\n        return len(valid), len(items) - len(valid)\n\n    @abstractmethod\n    def parse(self, raw: str) -> list[PriceItem]:\n        \"\"\"Required step.\"\"\"\n\n    def adjust(self, item: PriceItem) -> PriceItem:\n        \"\"\"Optional hook – returns the item unchanged by default.\"\"\"\n        return item\n\n    @staticmethod\n    def _is_valid(item: PriceItem) -> bool:\n        return bool(item.name) and item.price > 0\n\n    def _save(self, items: list[PriceItem]) -> None:\n        for i in items:\n            print(f\"{type(self).__name__}: {i.name} = {i.price:.2f} PLN/{i.unit}\")\n\n\nclass FarmCsvImport(PriceListImport):\n    def parse(self, raw: str) -> list[PriceItem]:\n        rows = (line.split(\";\") for line in raw.splitlines() if line)\n        return [PriceItem(name, unit, float(price.replace(\",\", \".\"))) for name, unit, price in rows]\n\n\nclass DairyJsonImport(PriceListImport):\n    def parse(self, raw: str) -> list[PriceItem]:\n        return [PriceItem(**row) for row in json.loads(raw)]\n\n    def adjust(self, item: PriceItem) -> PriceItem:\n        return replace(item, price=round(item.price * 1.02, 2))  # 2% cooling fee\n\n\nprint(FarmCsvImport().run(\"cheese;kg;24,50\\npotatoes;kg;3,20\\nonions;kg;-1\"))  # (2, 1)\nprint(DairyJsonImport().run('[{\"name\": \"cream\", \"unit\": \"l\", \"price\": 12.0}]'))  # (1, 0)"}]}]}]},"toc":[{"id":"the-problem-two-imports-one-logic-two-copies","text":"The problem: two imports, one logic, two copies","level":2,"locked":false},{"id":"the-solution-a-skeleton-in-the-base-class","text":"The solution: a skeleton in the base class","level":2,"locked":false},{"id":"implementation-in-five-languages","text":"Implementation in five languages","level":2,"locked":false},{"id":"a-template-without-inheritance","text":"A template without inheritance","level":2,"locked":true},{"id":"step-by-step","text":"Step by step","level":2,"locked":true},{"id":"template-method-vs-strategy","text":"Template Method vs Strategy","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":"test-yourself","text":"Test yourself","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":36,"visibleBlocks":15,"resources":[{"id":"6b0857bf3c96f2d34d0b42cd","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/template-method","embedUrl":null,"title":"Metoda szablonowa / Template Method","description":"Metoda szablonowa to behawioralny wzorzec projektowy definiujący szkielet algorytmu w klasie bazowej, ale pozwalający podklasom nadpisać pewne etapy tego algorytmu bez konieczności zmiany jego struktury.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["template-method"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":60,"verifiedAt":"2026-11-26T11:26:14.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:02.417Z","updatedAt":"2026-11-26T16:01:02.417Z"},{"id":"6b0857c33c96f2d34d0b4666","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL16942701W","embedUrl":null,"title":"Head First design patterns","description":"","author":"Eric Freeman, Elisabeth Freeman, Kathy Sierra, Bert Bates","thumbnailUrl":"https://covers.openlibrary.org/b/id/388950-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":["java"],"tags":["book","design-patterns"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"2004-01-01T00:00:00.000Z","popularity":62,"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":"6b0857be3c96f2d34d0b4233","type":"article","provider":"web","url":"https://java-design-patterns.com/patterns","embedUrl":null,"title":"Design Pattern Catalog","description":"Discover the full list of Java design patterns. This comprehensive guide provides you with all the information you need to master pattern implementation in your Java applications.","author":"Java Design Patterns","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":[],"techs":["java"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":70,"verifiedAt":"2026-11-26T11:26:34.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"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":[],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"gof-behavioral","title":"GoF behavioral patterns","items":[{"slug":"strategy","title":"Strategy: interchangeable algorithms instead of an if-else ladder","current":false},{"slug":"observer","title":"Observer: notify everyone without knowing anyone","current":false},{"slug":"command","title":"Command: a request wrapped in an object","current":false},{"slug":"state","title":"State: an object that changes behaviour with its life stage","current":false},{"slug":"template-method","title":"Template Method: a fixed recipe, interchangeable ingredients","current":true},{"slug":"iterator","title":"Iterator: walking a collection without looking inside","current":false},{"slug":"chain-of-responsibility","title":"Chain of Responsibility: pass it on until someone takes care of it","current":false},{"slug":"mediator","title":"Mediator: components talk through a coordinator","current":false},{"slug":"memento","title":"Memento: a state snapshot without breaking encapsulation","current":false},{"slug":"visitor","title":"Visitor: new operations without changing classes","current":false}]}],"prev":{"slug":"state","title":"State: an object that changes behaviour with its life stage"},"next":{"slug":"iterator","title":"Iterator: walking a collection without looking inside"},"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}]}}