8000 java-design-patterns/factory-method at master · augur/java-design-patterns · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"allShortcutsEnabled":false,"path":"factory-method","repo":{"id":163204401,"defaultBranch":"master","name":"java-design-patterns","ownerLogin":"augur","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2018-12-26T17:52:07.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1299692?v=4","public":true,"private":false,"isOrgOwned":false},"currentUser":null,"refInfo":{"name":"master","listCacheKey":"v0:1617001162.704","canEdit":false,"refType":"branch","currentOid":"a6749cb63e97cab38f7751ce2d164dfa9b4beb3b"},"tree":{"items":[{"name":"etc","path":"factory-method/etc","contentType":"directory"},{"name":"src","path":"factory-method/src","contentType":"directory"},{"name":".gitignore","path":"factory-method/.gitignore","contentType":"file"},{"name":"README.md","path":"factory-method/README.md","contentType":"file"},{"name":"pom.xml","path":"factory-method/pom.xml","contentType":"file"}],"templateDirectorySuggestionUrl":null,"readme":{"displayName":"README.md","richText":"\u003carticle class=\"markdown-body entry-content container-lg\" itemprop=\"text\"\u003e\u003cmarkdown-accessiblity-table\u003e\u003ctable\u003e\n \u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003elayout\u003c/th\u003e\n \u003cth\u003etitle\u003c/th\u003e\n \u003cth\u003efolder\u003c/th\u003e\n \u003cth\u003epermalink\u003c/th\u003e\n \u003cth\u003ecategories\u003c/th\u003e\n \u003cth\u003etags\u003c/th\u003e\n \u003c/tr\u003e\n \u003c/thead\u003e\n \u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003epattern\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003eFactory Method\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003efactory-method\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003e/patterns/factory-method/\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003eCreational\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003e\u003ctable\u003e\n \u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003eJava\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003eDifficulty-Beginner\u003c/div\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cdiv dir=\"auto\"\u003eGang Of Four\u003c/div\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003c/tbody\u003e\n\u003c/table\u003e\u003c/markdown-accessiblity-table\u003e\n\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eAlso known as\u003c/h2\u003e\u003ca id=\"user-content-also-known-as\" class=\"anchor\" aria-label=\"Permalink: Also known as\" href=\"#also-known-as\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eVirtual Constructor\u003c/p\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eIntent\u003c/h2\u003e\u003ca id=\"user-content-intent\" class=\"anchor\" aria-label=\"Permalink: Intent\" href=\"#intent\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eDefine an interface for creating an object, but let subclasses\ndecide which class to instantiate. Factory Method lets a class defer\ninstantiation to subclasses.\u003c/p\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eExplanation\u003c/h2\u003e\u003ca id=\"user-content-explanation\" class=\"anchor\" aria-label=\"Permalink: Explanation\" href=\"#explanation\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eReal world example\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp dir=\"auto\"\u003eBlacksmith manufactures weapons. Elves require Elvish weapons and orcs require Orcish weapons. Depending on the customer at hand the right type of blacksmith is summoned.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp dir=\"auto\"\u003eIn plain words\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp dir=\"auto\"\u003eIt provides a way to delegate the instantiation logic to child classes.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp dir=\"auto\"\u003eWikipedia says\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp dir=\"auto\"\u003eIn class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eProgrammatic Example\u003c/strong\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eTaking our blacksmith example above. First of all we have a blacksmith interface and some implementations for it\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-java notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"public interface Blacksmith {\n Weapon manufactureWeapon(WeaponType weaponType);\n}\n\npublic class ElfBlacksmith implements Blacksmith {\n public Weapon manufactureWeapon(WeaponType weaponType) {\n return new ElfWeapon(weaponType);\n }\n}\n\npublic class OrcBlacksmith implements Blacksmith {\n public Weapon manufactureWeapon(WeaponType weaponType) {\n return new OrcWeapon(weaponType);\n }\n}\"\u003e\u003cpre\u003e\u003cspan class=\"pl-k\"\u003epublic\u003c/span\u003e \u003cspan class=\"pl-k\"\u003einterface\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eBlacksmith\u003c/span\u003e {\n \u003cspan class=\"pl-smi\"\u003eWeapon\u003c/span\u003e \u003cspan class=\"pl-en\"\u003emanufactureWeapon\u003c/span\u003e(\u003cspan class=\"pl-smi\"\u003eWeaponType\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eweaponType\u003c/span\u003e);\n}\n\n\u003cspan class=\"pl-k\"\u003epublic\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eclass\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eElfBlacksmith\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimplements\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eBlacksmith\u003c/span\u003e {\n \u003cspan class=\"pl-k\"\u003epublic\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eWeapon\u003c/span\u003e \u003cspan class=\"pl-en\"\u003emanufactureWeapon\u003c/span\u003e(\u003cspan class=\"pl-smi\"\u003eWeaponType\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eweaponType\u003c/span\u003e) {\n \u003cspan class=\"pl-k\"\u003ereturn\u003c/span\u003e \u003cspan class=\"pl-k\"\u003enew\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eElfWeapon\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eweaponType\u003c/span\u003e);\n }\n}\n\n\u003cspan class=\"pl-k\"\u003epublic\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eclass\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eOrcBlacksmith\u003c/span\u003e \u003cspan class=\"pl-k\"\u003eimplements\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eBlacksmith\u003c/span\u003e {\n \u003cspan class=\"pl-k\"\u003epublic\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eWeapon\u003c/span\u003e \u003cspan class=\"pl-en\"\u003emanufactureWeapon\u003c/span\u003e(\u003cspan class=\"pl-smi\"\u003eWeaponType\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eweaponType\u003c/span\u003e) {\n \u003cspan class=\"pl-k\"\u003ereturn\u003c/span\u003e \u003cspan class=\"pl-k\"\u003enew\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eOrcWeapon\u003c/span\u003e(\u003cspan class=\"pl-s1\"\u003eweaponType\u003c/span\u003e);\n }\n}\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eNow as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured\u003c/p\u003e\n\u003cdiv class=\"highlight highlight-source-java notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"Blacksmith blacksmith = new ElfBlacksmith();\nblacksmith.manufactureWeapon(WeaponType.SPEAR);\nblacksmith.manufactureWeapon(WeaponType.AXE);\n// Elvish weapons are created\"\u003e\u003cpre\u003e\u003cspan class=\"pl-smi\"\u003eBlacksmith\u003c/span\u003e \u003cspan class=\"pl-s1\"\u003eblacksmith\u003c/span\u003e = \u003cspan class=\"pl-k\"\u003enew\u003c/span\u003e \u003cspan class=\"pl-smi\"\u003eElfBlacksmith\u003c/span\u003e();\n\u003cspan class=\"pl-s1\"\u003eblacksmith\u003c/span\u003e.\u003cspan class=\"pl-en\"\u003emanufactureWeapon\u003c/span\u003e(\u003cspan class=\"pl-smi\"\u003eWeaponType\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eSPEAR\u003c/span\u003e);\n\u003cspan class=\"pl-s1\"\u003eblacksmith\u003c/span\u003e.\u003cspan class=\"pl-en\"\u003emanufactureWeapon\u003c/span\u003e(\u003cspan class=\"pl-smi\"\u003eWeaponType\u003c/span\u003e.\u003cspan class=\"pl-c1\"\u003eAXE\u003c/span\u003e);\n\u003cspan class=\"pl-c\"\u003e// Elvish weapons are created\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eApplicability\u003c/h2\u003e\u003ca id=\"user-content-applicability\" class=\"anchor\" aria-label=\"Permalink: Applicability\" href=\"#applicability\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eUse the Factory Method pattern when\u003c/p\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003ea class can't anticipate the class of objects it must create\u003c/li\u003e\n\u003cli\u003ea class wants its subclasses to specify the objects it creates\u003c/li\u003e\n\u003cli\u003eclasses delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate\u003c/li\u003e\n\u003c/ul\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003ePresentations\u003c/h2\u003e\u003ca id=\"user-content-presentations\" class=\"anchor\" aria-label=\"Permalink: Presentations\" href=\"#presentations\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003e\u003ca href=\"/augur/java-design-patterns/blob/master/factory-method/etc/presentation.html\"\u003eFactory Method Pattern\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eReal world examples\u003c/h2\u003e\u003ca id=\"user-content-real-world-examples\" class=\"anchor\" aria-label=\"Permalink: Real world examples\" href=\"#real-world-examples\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003e\u003ca href=\"http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getInstance--\" rel=\"nofollow\"\u003ejava.util.Calendar\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"http://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.html#getBundle-java.lang.String-\" rel=\"nofollow\"\u003ejava.util.ResourceBundle\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"http://docs.oracle.com/javase/8/docs/api/java/text/NumberFormat.html#getInstance--\" rel=\"nofollow\"\u003ejava.text.NumberFormat\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"http://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html#forName-java.lang.String-\" rel=\"nofollow\"\u003ejava.nio.charset.Charset\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"http://docs.oracle.com/javase/8/docs/api/java/net/URLStreamHandlerFactory.html#createURLStreamHandler-java.lang.String-\" rel=\"nofollow\"\u003ejava.net.URLStreamHandlerFactory\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://docs.oracle.com/javase/8/docs/api/java/util/EnumSet.html#of-E-\" rel=\"nofollow\"\u003ejava.util.EnumSet\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/JAXBContext.html#createMarshaller--\" rel=\"nofollow\"\u003ejavax.xml.bind.JAXBContext\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eCredits\u003c/h2\u003e\u003ca id=\"user-content-credits\" class=\"anchor\" aria-label=\"Permalink: Credits\" href=\"#credits\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003e\u003ca href=\"http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612\" rel=\"nofollow\"\u003eDesign Patterns: Elements of Reusable Object-Oriented Software\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/article\u003e","errorMessage":null,"headerInfo":{"toc":[{"level":2,"text":"Also known as","anchor":"also-known-as","htmlText":"Also known as"},{"level":2,"text":"Intent","anchor":"intent","htmlText":"Intent"},{"level":2,"text":"Explanation","anchor":"explanation","htmlText":"Explanation"},{"level":2,"text":"Applicability","anchor":"applicability","htmlText":"Applicability"},{"level":2,"text":"Presentations","anchor":"presentations","htmlText":"Presentations"},{"level":2,"text":"Real world examples","anchor":"real-world-examples","htmlText":"Real world examples"},{"level":2,"text":"Credits","anchor":"credits","htmlText":"Credits"}],"siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Faugur%2Fjava-design-patterns%2Ftree%2Fmaster%2Ffactory-method"}},"totalCount":5,"showBranchInfobar":true},"fileTree":{"":{"items":[{"name":"abstract-document","path":"abstract-document","contentType":"directory"},{"name":"abstract-factory","path":"abstract-factory","contentType":"directory"},{"name":"acyclic-visitor","path":"acyclic-visitor","contentType":"directory"},{"name":"adapter","path":"adapter","contentType":"directory"},{"name":"aggregator-microservices","path":"aggregator-microservices","contentType":"directory"},{"name":"ambassador","path":"ambassador","contentType":"directory"},{"name":"api-gateway","path":"api-gateway","contentType":"directory"},{"name":"async-method-invocation","path":"async-method-invocation","contentType":"directory"},{"name":"balking","path":"balking","contentType":"directory"},{"name":"bridge","path":"bridge","contentType":"directory"},{"name":"builder","path":"builder","contentType":"directory"},{"name":"business-delegate","path":"business-delegate","contentType":"directory"},{"name":"caching","path":"caching","contentType":"directory"},{"name":"callback","path":"callback","contentType":"directory"},{"name":"chain","path":"chain","contentType":"directory"},{"name":"collection-pipeline","path":"collection-pipeline","contentType":"directory"},{"name":"command","path":"command","contentType":"directory"},{"name":"composite","path":"composite","contentType":"directory"},{"name":"converter","path":"converter","contentType":"directory"},{"name":"cqrs","path":"cqrs","contentType":"directory"},{"name":"dao","path":"dao","contentType":"directory"},{"name":"data-bus","path":"data-bus","contentType":"directory"},{"name":"data-mapper","path":"data-mapper","contentType":"directory"},{"name":"data-transfer-object","path":"data-transfer-object","contentType":"directory"},{"name":"decorator","path":"decorator","contentType":"directory"},{"name":"delegation","path":"delegation","contentType":"directory"},{"name":"dependency-injection","path":"dependency-injection","contentType":"directory"},{"name":"dirty-flag","path":"dirty-flag","contentType":"directory"},{"name":"double-checked-locking","path":"double-checked-locking","contentType":"directory"},{"name":"double-dispatch","path":"double-dispatch","contentType":"directory"},{"name":"eip-aggregator","path":"eip-aggregator","contentType":"directory"},{"name":"eip-message-channel","path":"eip-message-channel","contentType":"directory"},{"name":"eip-publish-subscribe","path":"eip-publish-subscribe","contentType":"directory"},{"name":"eip-splitter","path":"eip-splitter","contentType":"directory"},{"name":"eip-wire-tap","path":"eip-wire-tap","contentType":"directory"},{"name":"event-aggregator","path":"event-aggregator","contentType":"directory"},{"name":"event-asynchronous","path":"event-asynchronous","contentType":"directory"},{"name":"event-driven-architecture","path":"event-driven-architecture","contentType":"directory"},{"name":"event-queue","path":"event-queue","contentType":"directory"},{"name":"event-sourcing","path":"event-sourcing","contentType":"directory"},{"name":"execute-around","path":"execute-around","contentType":"directory"},{"name":"extension-objects","path":"extension-objects","contentType":"directory"},{"name":"facade","path":"facade","contentType":"directory"},{"name":"factory-kit","path":"factory-kit","contentType":"directory"},{"name":"factory-method","path":"factory-method","contentType":"directory"},{"name":"feature-toggle","path":"feature-toggle","contentType":"directory"},{"name":"fluentinterface","path":"fluentinterface","contentType":"directory"},{"name":"flux","path":"flux","contentType":"directory"},{"name":"flyweight","path":"flyweight","contentType":"directory"},{"name":"front-controller","path":"front-controller","contentType":"directory"},{"name":"guarded-suspension","path":"guarded-suspension","contentType":"directory"},{"name":"half-sync-half-async","path":"half-sync-half-async","contentType":"directory"},{"name":"hexagonal","path":"hexagonal","contentType":"directory"},{"name":"intercepting-filter","path":"intercepting-filter","contentType":"directory"},{"name":"interpreter","path":"interpreter","contentType":"directory"},{"name":"iterator","path":"iterator","contentType":"directory"},{"name":"layers","path":"layers","contentType":"directory"},{"name":"lazy-loading","path":"lazy-loading","contentType":"directory"},{"name":"marker","path":"marker","contentType":"directory"},{"name":"mediator","path":"mediator","contentType":"directory"},{"name":"memento","path":"memento","contentType":"directory"},{"name":"model-view-controller","path":"model-view-controller","contentType":"directory"},{"name":"model-view-presenter","path":"model-view-presenter","contentType":"directory"},{"name":"module","path":"module","contentType":"directory"},{"name":"monad","path":"monad","contentType":"directory"},{"name":"monostate","path":"monostate","contentType":"directory"},{"name":"multiton","path":"multiton","contentType":"directory"},{"name":"mute-idiom","path":"mute-idiom","contentType":"directory"},{"name":"mutex","path":"mutex","contentType":"directory"},{"name":"naked-objects","path":"naked-objects","contentType":"directory"},{"name":"null-object","path":"null-object","contentType":"directory"},{"name":"object-mother","path":"object-mother","contentType":"directory"},{"name":"object-pool","path":"object-pool","contentType":"directory"},{"name":"observer","path":"observer","contentType":"directory"},{"name":"page-object","path":"page-object","contentType":"directory"},{"name":"partial-response","path":"partial-response","contentType":"directory"},{"name":"poison-pill","path":"poison-pill","contentType":"directory"},{"name":"private-class-data","path":"private-class-data","contentType":"directory"},{"name":"producer-consumer","path":"producer-consumer","contentType":"directory"},{"name":"promise","path":"promise","contentType":"directory"},{"name":"property","path":"property","contentType":"directory"},{"name":"prototype","path":"prototype","contentType":"directory"},{"name":"proxy","path":"proxy","contentType":"directory"},{"name":"queue-load-leveling","path":"queue-load-leveling","contentType":"directory"},{"name":"reactor","path":"reactor","contentType":"directory"},{"name":"reader-writer-lock","path":"reader-writer-lock","contentType":"directory"},{"name":"repository","path":"repository","contentType":"directory"},{"name":"resource-acquisition-is-initialization","path":"resource-acquisition-is-initialization","contentType":"directory"},{"name":"retry","path":"retry","contentType":"directory"},{"name":"semaphore","path":"semaphore","contentType":"directory"},{"name":"servant","path":"servant","contentType":"directory"},{"name":"serverless","path":"serverless","contentType":"directory"},{"name":"service-layer","path":"service-layer","contentType":"directory"},{"name":"service-locator","path":"service-locator","contentType":"directory"},{"name":"singleton","path":"singleton","contentType":"directory"},{"name":"spatial-partition","path":"spatial-partition","contentType":"directory"},{"name":"specification","path":"specification","contentType":"directory"},{"name":"state","path":"state","contentType":"directory"},{"name":"step-builder","path":"step-builder","contentType":"directory"},{"name":"strategy","path":"strategy","contentType":"directory"},{"name":"template-method","path":"template-method","contentType":"directory"},{"name":"thread-pool","path":"thread-pool","contentType":"directory"},{"name":"throttling","path":"throttling","contentType":"directory"},{"name":"tls","path":"tls","contentType":"directory"},{"name":"tolerant-reader","path":"tolerant-reader","contentType":"directory"},{"name":"trampoline","path":"trampoline","contentType":"directory"},{"name":"twin","path":"twin","contentType":"directory"},{"name":"unit-of-work","path":"unit-of-work","contentType":"directory"},{"name":"value-object","path":"value-object","contentType":"directory"},{"name":"visitor","path":"visitor","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"CODE_COVERAGE.md","path":"CODE_COVERAGE.md","contentType":"file"},{"name":"CONTRIBUTING.MD","path":"CONTRIBUTING.MD","contentType":"file"},{"name":"LICENSE.md","path":"LICENSE.md","contentType":"file"},{"name":"PULL_REQUEST_TEMPLATE.md","path":"PULL_REQUEST_TEMPLATE.md","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"checkstyle-suppressions.xml","path":"checkstyle-suppressions.xml","contentType":"file"},{"name":"checkstyle.xml","path":"checkstyle.xml","contentType":"file"},{"name":"exclude-pmd.properties","path":"exclude-pmd.properties","contentType":"file"},{"name":"faq.md","path":"faq.md","contentType":"file"},{"name":"pom.xml","path":"pom.xml","contentType":"file"},{"name":"update-ghpages.sh","path":"update-ghpages.sh","contentType":"file"}],"totalCount":123}},"fileTreeProcessingTime":7.8066699999999996,"foldersToFetch":[],"treeExpanded":true,"symbolsExpanded":false,"csrf_tokens":{"/augur/java-design-patterns/branches":{"post":"z5Z0o7bxczXQe9r7U8kYJf5M1he7Jlr1UvlD0c7kQw2pUjpUXv3NqqyRY3Ee65M_LwpMG__ucARG8Q4tejwvxw"},"/augur/java-design-patterns/branches/fetch_and_merge/master":{"post":"FvxmUOFoOEOT4Q-uDWgtc3FpmFmnseJHY13SO7SjyrlapkNpNHJzyWzlDnIa2y6hsLyjerrzWi96gOVyWbTP1w"},"/augur/java-design-patterns/branches/fetch_and_merge/master?discard_changes=true":{"post":"mYZZZFD5QVECaCcND9z9HN_NUYlWZeHIijghLAdf6ObV3HxdheMK2_1sJtEYb_7OHhhqqksnWaCT5RZl6kjtiA"}}},"title":"java-design-patterns/factory-method at master · augur/java-design-patterns","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-b84e9496fc59.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0