{"id":307,"date":"2019-01-06T13:08:55","date_gmt":"2019-01-06T13:08:55","guid":{"rendered":"http:\/\/berkkibarer.com\/?p=307"},"modified":"2019-01-07T06:27:05","modified_gmt":"2019-01-07T06:27:05","slug":"reduced-structural-complexity-with-examples","status":"publish","type":"post","link":"https:\/\/www.berkkibarer.com\/?p=307","title":{"rendered":"Reduced Structural Complexity With Examples"},"content":{"rendered":"\n<p>Code quality is -should be- one of the main concerns of a software developer. While designing the internal structure, it is important to avoid increasing the structural complexity -cyclomatic complexity, cognitive complexity, halstead volume, maintainability index and such&#8230;- which exposes to reliability, maintainability and testability problems.<\/p>\n\n\n\n<p>Factory pattern design seemed  like a good place to start explaining how to work on complexity problems. The reason, <a rel=\"noreferrer noopener\" aria-label=\"G\u00fcrel  (opens in a new tab)\" href=\"http:\/\/gurel.kaynak.link\/\" target=\"_blank\">G\u00fcrel <\/a>and I picked factory pattern, is because<a rel=\"noreferrer noopener\" aria-label=\" its most common usage (opens in a new tab)\" href=\"https:\/\/www.tutorialspoint.com\/design_pattern\/factory_pattern.htm\" target=\"_blank\"> its most common usage<\/a> -no offense, this is just one way of doing it :)- simply turns the code into an if\/else farm in no time. As you would imagine, this kind of approach aggravates the complexity.<\/p>\n\n\n\n<p>With my dear friend and colleague <a rel=\"noreferrer noopener\" aria-label=\"G\u00fcrel Kaynak (opens in a new tab)\" href=\"http:\/\/gurel.kaynak.link\" target=\"_blank\">G\u00fcrel Kaynak<\/a>, we prepared a <a rel=\"noreferrer noopener\" aria-label=\"factory pattern example (opens in a new tab)\" href=\"http:\/\/gurel.kaynak.link\/2019\/01\/05\/complexity-free-factory-pattern\/\" target=\"_blank\">factory pattern example<\/a> in both Java and Python just to indicate an alternative way which comes as a complexity-free version with lazy initialization (delegates). This approach uses Maps to replace the conditional statements and manage the passed dependencies as strict as possible via Enum types.<\/p>\n\n\n\n<p>To spice it up a little bit, it is always welcome to implement a caching system or even prototype pattern when creating an object comes at a high cost.<\/p>\n\n\n\n<p>Please check out the link below for the examples;<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><a href=\"http:\/\/gurel.kaynak.link\/2019\/01\/05\/complexity-free-factory-pattern\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Complexity-free Factory Pattern Examples (opens in a new tab)\">Complexity-free Factory Pattern Examples<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n ","protected":false},"excerpt":{"rendered":"<p>Code quality is -should be- one of the main concerns of a software developer. While designing the internal structure, it is important to avoid increasing the structural complexity -cyclomatic complexity, cognitive complexity, halstead volume, maintainability index and such&hellip;- which exposes to reliability, maintainability and testability problems. Factory pattern design seemed like a good place to start explaining how to work on complexity problems. The reason, G&uuml;rel and I picked factory pattern, is because its most common usage -no offense, this is just one way of doing it :)- simply turns&hellip;<\/p>\n","protected":false},"author":1,"featured_media":320,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[1,20],"tags":[160,161,162,165,163,164,158],"class_list":["post-307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-published","category-thoughts","tag-complexity-free","tag-complexity-safe","tag-factory-pattern","tag-gurel-kaynak","tag-java","tag-python","tag-structural-complexity"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307"}],"version-history":[{"count":10,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions\/322"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/media\/320"}],"wp:attachment":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}