{"id":2349,"date":"2019-11-06T08:57:59","date_gmt":"2019-11-06T05:57:59","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=2349"},"modified":"2024-12-16T22:32:32","modified_gmt":"2024-12-16T19:32:32","slug":"abstract-factory-pattern","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/hi\/2019\/11\/06\/abstract-factory-pattern\/","title":{"rendered":"Abstract Factory Pattern"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2353\" src=\"https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2019\/11\/kit.jpg\" alt=\"\" width=\"420\" height=\"315\" srcset=\"https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2019\/11\/kit.jpg 420w, https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2019\/11\/kit-300x225.jpg 300w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/p>\n<p><b>Abstract factory<\/b>&#8211; provides an interface for creating related objects without specifying specific classes.<\/p>\n<p>I really like the alternative name of this pattern &#8211; <b>Kit<\/b><\/p>\n<p>It is very similar to <b>Factory Method<\/b>, however <b>Abstract Factories<\/b> must describe the relationship between the objects being created, otherwise it is simply an anti-pattern <b>God Object<\/b>, which creates everything in a row in a haphazard manner.<\/p>\n<p>Let&#8217;s imagine developing an AR framework for glasses, we display indoor navigation arrows, icons of stores, interesting places, windows and buttons with information about a place where the user is currently located on the screen.<\/p>\n<p>At the same time, we need the ability to customize the appearance and behavior of AR environment controls. This is exactly the case where we need to use the <b>Set<\/b> pattern.<\/p>\n<p>Let&#8217;s write the interface of the <b>Abstract Factory<\/b> and <b>Abstract Products<\/b> &#8211; parent protocols, elements of the AR environment:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>protocol ARFactory {\n    func arrow() -&gt; ARArrow\n    func icon() -&gt; ARIcon\n    func button() -&gt; ARButton\n    func window() -&gt; ARWindow\n}\n\nprotocol ARArrow {\n    var image: { get }\n    func handleSelection()\n}\n\nprotocol ARIcon {\n    var image: { get }\n    var title: String\n}\n\nprotocol ARButton {\n    var title: String\n    func handleSelection()\n}\n\nprotocol ARWindow {\n    var title: String\n    var draw(canvas: Canvas)\n}\n<\/code><\/pre>\n<\/div>\n<p>Now, set developers will need to implement a Concrete Factory based on the Abstract Factory interface, and all elements will have to be implemented together; other parts of the application will be able to work with the factory without changing their code.<\/p>\n<h3>Sources<\/h3>\n<p><a href=\"https:\/\/refactoring.guru\/ru\/design-patterns\/abstract-factory\" target=\"_blank\" rel=\"noopener\">https:\/\/refactoring.guru\/ru\/design-patterns \/abstract-factory<\/a><br \/><a href=\"https:\/\/www.amazon.com\/Design-Patterns-Elements-Reusable-Object-Oriented\/dp\/0201633612\" target=\"_blank\" rel=\"noopener\">https:\/\/www.amazon.com\/Design-Patterns-Elements-Reusable-Object-Oriented\/dp\/0201633612<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Abstract factory&#8211; provides an interface for creating related objects without specifying specific classes. I really like the alternative name of this pattern &#8211; Kit It is very similar to Factory Method, however Abstract Factories must describe the relationship between the objects being created, otherwise it is simply an anti-pattern God Object, which creates everything in<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/hi\/2019\/11\/06\/abstract-factory-pattern\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Abstract Factory Pattern&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[129,95],"class_list":["post-2349","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-abstract-factory","tag-patterns","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"hi","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/comments?post=2349"}],"version-history":[{"count":11,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2349\/revisions"}],"predecessor-version":[{"id":3933,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2349\/revisions\/3933"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/media?parent=2349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/categories?post=2349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/tags?post=2349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}