{"slug":"factory-method","group":"creational","title":"Factory Method","short":"Subclasses decide which concrete object gets created; callers depend only on a shared interface.","icon":"factory","aliases":[],"order":101,"status":"available","articleCount":3,"groupTitle":"Creational patterns","intro":"","servedLang":"en","primaryArticle":{"id":"6b08bd3480884893657cc960","slug":"factory-method","title":"Factory Method – let the subclass decide what gets created","summary":"Factory Method separates the algorithm that uses an object from the decision about which exact object is created. A ticket booking example in C#, TypeScript, Java, Go and Python.","servedLang":"en","availableLangs":["pl","en"],"topics":["factory-method","abstract-factory","template-method"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","creational","factory-method","polymorphism"],"level":"intermediate","kind":"article","access":"public","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":11,"stats":{"views":6,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:56.030Z","updatedAt":"2026-11-27T13:05:24.185Z","challengeCount":1,"quizCount":0},"articles":[{"id":"6b08bd2e80884893657cc8d4","slug":"abstract-factory","title":"Abstract Factory – whole families of objects that fit together","summary":"Abstract Factory creates a complete set of related objects from one family and makes sure nobody mixes parts from different sets. An example with two payment provider integrations.","servedLang":"en","availableLangs":["pl","en"],"topics":["abstract-factory","factory-method","singleton"],"techs":["dotnet","typescript","java","go","python"],"tags":["gof","creational","abstract-factory","product-families"],"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":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:13:50.779Z","updatedAt":"2026-11-27T10:05:03.622Z","relation":{"position":1,"primary":false,"mainTopic":{"slug":"abstract-factory","title":"Abstract Factory"}}},{"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":3,"primary":false,"mainTopic":{"slug":"flyweight","title":"Flyweight"}}}],"challenges":[{"id":"6b0857af5a2625e44ecaad0a","slug":"notification-factory","title":"Notification factory","summary":"Implement Factory Method: every notification service decides which channel (e-mail, SMS, push) it creates.","servedLang":"en","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"}],"resources":[{"id":"6b0857a53c96f2d34d0b321d","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=EcFVTgRHJLM","embedUrl":"https://www.youtube-nocookie.com/embed/EcFVTgRHJLM","title":"Factory Method Pattern – Design Patterns (ep 4)","description":"","author":"Christopher Okhravi","thumbnailUrl":"https://i.ytimg.com/vi/EcFVTgRHJLM/hqdefault.jpg","durationSec":null,"lang":"en","topics":["factory-method"],"techs":["general"],"tags":[],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"seed","publishedAt":null,"popularity":0,"verifiedAt":"2026-11-26T00:00:00.000Z","curated":true,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:37.643Z","updatedAt":"2026-11-26T16:00:37.643Z"},{"id":"6b0857be3c96f2d34d0b41dd","type":"article","provider":"web","url":"https://refactoring.guru/design-patterns/factory-method","embedUrl":null,"title":"Factory Method","description":"Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"en","topics":["factory-method"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":80,"verifiedAt":"2026-11-26T11:25:59.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"},{"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":"6b0857c83c96f2d34d0b49f2","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=IlmOokWznyI","embedUrl":"https://www.youtube-nocookie.com/embed/IlmOokWznyI","title":"Design Patterns in Dynamic Languages | Code Walks 016","description":"Do dynamically typed languages really need design patterns? 02:43 The short version of the argument 03:04 Strategy pattern 05:25 Factory pattern GEAR USED ► MIC: RØDE SmartLav+ http://amzn.to/21nVI3o ► CAMERA: iPhone 6 http://amzn.to/1UeVCXv Original upload date: Jun 24, 2016","author":"Christopher Okhravi","thumbnailUrl":"https://i.ytimg.com/vi/IlmOokWznyI/hqdefault.jpg","durationSec":null,"lang":"en","topics":["strategy"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"youtube-rss","publishedAt":"2016-07-16T09:26:14.000Z","popularity":59,"verifiedAt":"2026-11-26T10:57:18.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:10.095Z","updatedAt":"2026-11-26T16:01:10.095Z"},{"id":"6b0857be3c96f2d34d0b4215","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/factory-method","embedUrl":null,"title":"Metoda wytwórcza / Factory Method","description":"Metoda wytwórcza jest kreacyjnym wzorcem projektowym, który udostępnia interfejs do tworzenia obiektów w ramach klasy bazowej, ale pozwala podklasom zmieniać typ tworzonych obiektów.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["factory-method"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":75,"verifiedAt":"2026-11-26T11:26:07.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"}],"resourceGroups":[{"type":"video","items":[{"id":"6b0857a53c96f2d34d0b321d","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=EcFVTgRHJLM","embedUrl":"https://www.youtube-nocookie.com/embed/EcFVTgRHJLM","title":"Factory Method Pattern – Design Patterns (ep 4)","description":"","author":"Christopher Okhravi","thumbnailUrl":"https://i.ytimg.com/vi/EcFVTgRHJLM/hqdefault.jpg","durationSec":null,"lang":"en","topics":["factory-method"],"techs":["general"],"tags":[],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"seed","publishedAt":null,"popularity":0,"verifiedAt":"2026-11-26T00:00:00.000Z","curated":true,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:37.643Z","updatedAt":"2026-11-26T16:00:37.643Z"},{"id":"6b0857c83c96f2d34d0b49f2","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=IlmOokWznyI","embedUrl":"https://www.youtube-nocookie.com/embed/IlmOokWznyI","title":"Design Patterns in Dynamic Languages | Code Walks 016","description":"Do dynamically typed languages really need design patterns? 02:43 The short version of the argument 03:04 Strategy pattern 05:25 Factory pattern GEAR USED ► MIC: RØDE SmartLav+ http://amzn.to/21nVI3o ► CAMERA: iPhone 6 http://amzn.to/1UeVCXv Original upload date: Jun 24, 2016","author":"Christopher Okhravi","thumbnailUrl":"https://i.ytimg.com/vi/IlmOokWznyI/hqdefault.jpg","durationSec":null,"lang":"en","topics":["strategy"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"youtube-rss","publishedAt":"2016-07-16T09:26:14.000Z","popularity":59,"verifiedAt":"2026-11-26T10:57:18.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:10.095Z","updatedAt":"2026-11-26T16:01:10.095Z"}]},{"type":"article","items":[{"id":"6b0857be3c96f2d34d0b41dd","type":"article","provider":"web","url":"https://refactoring.guru/design-patterns/factory-method","embedUrl":null,"title":"Factory Method","description":"Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"en","topics":["factory-method"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":80,"verifiedAt":"2026-11-26T11:25:59.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"},{"id":"6b0857be3c96f2d34d0b4215","type":"article","provider":"web","url":"https://refactoring.guru/pl/design-patterns/factory-method","embedUrl":null,"title":"Metoda wytwórcza / Factory Method","description":"Metoda wytwórcza jest kreacyjnym wzorcem projektowym, który udostępnia interfejs do tworzenia obiektów w ramach klasy bazowej, ale pozwala podklasom zmieniać typ tworzonych obiektów.","author":"Refactoring.Guru","thumbnailUrl":"https://refactoring.guru/pl/images/refactoring/social/facebook-share-preview.png?id=dbf9e98269595be86eb668f365be6868","durationSec":null,"lang":"pl","topics":["factory-method"],"techs":["general"],"tags":["design-patterns"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":75,"verifiedAt":"2026-11-26T11:26:07.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:59.965Z","updatedAt":"2026-11-26T16:00:59.965Z"}]},{"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"},{"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"}]}],"siblings":[{"slug":"factory-method","title":"Factory Method","icon":"factory","status":"available","current":true},{"slug":"abstract-factory","title":"Abstract Factory","icon":"boxes","status":"available","current":false},{"slug":"builder","title":"Builder","icon":"hammer","status":"available","current":false},{"slug":"prototype","title":"Prototype","icon":"copy","status":"available","current":false},{"slug":"singleton","title":"Singleton","icon":"circle-dot","status":"available","current":false}]}