{"id":250,"date":"2020-08-06T00:10:38","date_gmt":"2020-08-05T21:10:38","guid":{"rendered":"https:\/\/blog.gunlerveisler.gen.tr\/?p=250"},"modified":"2020-09-21T04:06:37","modified_gmt":"2020-09-21T01:06:37","slug":"without-an-if-notes","status":"publish","type":"post","link":"https:\/\/aliyargunes.com.tr\/blog\/without-an-if-notes\/","title":{"rendered":"&#8220;Without An If&#8221; Notes"},"content":{"rendered":"\n<p>Here is some notes which I took from a Google Tech Talks video: <\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"&quot;The Clean Code Talks  -- Inheritance, Polymorphism, &amp; Testing&quot;\" width=\"640\" height=\"480\" src=\"https:\/\/www.youtube.com\/embed\/4F72VULWFvc?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>When to use Polymorphism<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>if an object should behave differently based on its state<\/li><li>If you have to check the same condition in multiple places Use Conditionals<\/li><\/ul>\n\n\n\n<p><strong>-&gt; Mainly to do comparisons of primitive objects:<br><\/strong>&lt;, &gt;, ==, !=<\/p>\n\n\n\n<p>We&#8217;re going to focus on where the business logic should behave differently, that&#8217;s the interesting part.<\/p>\n\n\n\n<p>If you really want to be if free in your application, the thing you have to do is you got to make sure you don&#8217;t return the Null&#8217;s.<\/p>\n\n\n\n<p>What you need is to put an if statement over there to make sure you don&#8217;t dispatch a Null.<br>And that clutter your code. So we want to get away from that.<\/p>\n\n\n\n<p><strong>Don&#8217;t return error codes, instead throw an Exception.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Never return a null, instead return a Null Object, e. g. an empty list<br>Null&#8217;s are friends of your test but really your enemy inside of production code.<br>You really don&#8217;t get in a situation when you return Null, because when you return a Null from a method, you can&#8217;t dispatch off on a Null. You&#8217;ll get a NullPointerException. <strong>!!!<\/strong><\/p><\/blockquote>\n\n\n\n<p>If you have a method, the method needs to return some kind of an object that probably doesn&#8217;t do anything. Typical example of this would be like the Null Logger.<br>If I need to Log, I&#8217;am always logging except sometimes I get a re-logger that logs the file system and sometimes I get a logger to just eats all my messages and doesn&#8217;t do anything.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Polymorphism uses subclassing<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><br>&#8211;&gt; When you have deep inheritance hierarchies, that creates problems from not jus testability, also from understandability and a couple of other abilities probably as well. (It is a fine line!)<\/p><\/blockquote>\n\n\n\n<p><strong>Replace conditionals with polymorphism<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211;&gt; You have a conditional that chooses different behavior depending on the type of an object.<br>Typically the way this thing happens is you have some kind of field inside of your object. and then based on whether this field is said or a flag, you&#8217;d be headed differently.<\/p><\/blockquote>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211;&gt; Move each leg of the conditional to an overriding method in a subclass. Make the original method abstract.<\/p><\/blockquote>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class Example {\n\ndouble getSpeed() {\n\nswitch(_type) {\n\ncase EUROPEAN:\nreturn getBaseSpeed();\n\ncase AFRICAN:\nreturn getBaseSpeed() - getLoadFactor() * _numberOfCoconuts;\n\ncase NORWEGIAN_BLUE:\nreturn (_isNailed) ? 0 : getBaseSpeed(_voltage);\n\n}\nthrow new RuntimeException (&quot;Should be Unreachable&quot;);\n}\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"505\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide1.jpg\" alt=\"\" class=\"wp-image-253\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide1.jpg 875w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide1-300x173.jpg 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide1-768x443.jpg 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><figcaption>There already a type system!<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Model This &#8211;&gt; <strong>1 + 2 * 3<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"501\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide2.jpg\" alt=\"\" class=\"wp-image-254\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide2.jpg 873w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide2-300x172.jpg 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide2-768x441.jpg 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><figcaption>a tree<\/figcaption><\/figure>\n\n\n\n<p>Lets say we want to perform evaluate method on it which computes the result.<\/p>\n\n\n\n<p>evaluate() &#8211;&gt; computes the result of an expression<\/p>\n\n\n\n<p>This method computes the result of an expression.<\/p>\n\n\n\n<p><strong>Typical solution:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass Node {\n\nchar operator;\ndouble value;\nNode left;\nNode right;\n\ndouble evaluate() {\n\nswitch (operator) {\n\ncase '#': return value;\n\ncase '+': return left.evaluate() + right.evaluate();\n\ncase '*': return lef.evaluate() * right.evaluate();\n\n}\n}\n<\/pre><\/div>\n\n\n<p>There&#8217;s actually a bigger problem with this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"702\" height=\"401\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide3.jpg\" alt=\"\" class=\"wp-image-255\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide3.jpg 702w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide3-300x171.jpg 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/figure>\n\n\n\n<p>Graphical representation of this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"399\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide4.jpg\" alt=\"\" class=\"wp-image-256\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide4.jpg 592w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide4-300x202.jpg 300w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/figure>\n\n\n\n<p><strong>Notice couple of things in there<\/strong><\/p>\n\n\n\n<p>Our leaf nodes still have the left and right child and they&#8217;re pulling thing to nulls, and we already said that nodes are not a good idea in production code. And so we&#8217;re going to trip up over our Null values by having the possibilty of having an NPE. So you want to get rid of that.<\/p>\n\n\n\n<p>Also noticing something else which is the plus and the multiplication node has to keep around zero even though it&#8217;s a completely meaningless concept for a plus or multiplication to have zero associate.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1013\" height=\"841\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide5.jpg\" alt=\"\" class=\"wp-image-257\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide5.jpg 1013w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide5-300x249.jpg 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide5-768x638.jpg 768w\" sizes=\"(max-width: 1013px) 100vw, 1013px\" \/><\/figure>\n\n\n\n<p>So there is two different behaviors that are kind of fighting in here.<br><strong>The different behaviors are basically:<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211;&gt; operaiton node &#8211;&gt; you need your left and right child<br>&#8211;&gt; value node &#8211;&gt; you need only the value<\/p><\/blockquote>\n\n\n\n<p><br>you don&#8217;t need the value or I need the left and right but I never need both.<br>And that usually is a perfect example that you have a class that has multiple responsibilities all entangled inside of it and then there&#8217;s some kind of a polymorphic behavior going on but the polymorphic behavior is going on through fields and if statements not through polymorphism.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"501\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide6.jpg\" alt=\"\" class=\"wp-image-258\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide6.jpg 873w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide6-300x172.jpg 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide6-768x441.jpg 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure>\n\n\n\n<p>Now, we have a value node and operation node.<\/p>\n\n\n\n<p><strong>Operations and Values<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nabstract class Node {\n\nabstract double evaluate();\n\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass ValueNode extends Node {\n\ndouble value;\ndouble evaluate() {\n\nreturn value;\n\n}\n}\n<\/pre><\/div>\n\n\n<p><br>There is no if statements in there, there&#8217;s no possibility for a Null or an NPE or anything like that.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"505\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide7.jpg\" alt=\"\" class=\"wp-image-260\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide7.jpg 873w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide7-300x174.jpg 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide7-768x444.jpg 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/figure>\n\n\n\n<p><br>We still have the same problem as we had with the swallows in the previous example. And that is, that the behavior of the node changes based on a type. On this case, it&#8217;s the operator field. So dependending on what the operator field is our class behaves differently. And that&#8217;s something we want to avoid, rather we want to take advantage of the construct of a language which is the polymorphism to take advantage of this thing rather than encoding it using if statements.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"436\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide8.jpg\" alt=\"\" class=\"wp-image-261\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide8.jpg 618w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide8-300x212.jpg 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nabstract class Node {\n\nabstract double evaluate();\n\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass ValueNode extends Node {\n\ndouble value;\ndouble evaluate() {\n\nreturn value;\n\n}\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass abstract OpNode extends Node {\n\nNode left;\nNode right;\nabstract double evaluate();\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass AdditionNode extends OpNode {\n\ndouble evaluate() {\n\nreturn left.evaluate() + right.evaluate();\n}\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass MultiplicationNode extends OpNode {\n\ndouble evaluate() {\n\nreturn left.evaluate() * right.evaluate();\n}\n}\n<\/pre><\/div>\n\n\n<p>Keep in mind that in addition and multiplication nodes, you would also have to implement a toString method that it would know how to print the plus operator.<\/p>\n\n\n\n<p><strong>Notice what happens in here<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><br>&#8211;&gt; The possibility of an NPE has dissappeared, because opearion nodes needs a left and a right child, and therefore it will never throw NPE<br>&#8211;&gt; The Leaf Node doesn&#8217;t have a left and child and it will never throw NPE.<\/p><\/blockquote>\n\n\n\n<p>So we can really clean up the code simply by breaking it away into smaller subclasses that do individual pieces of work.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"871\" height=\"498\" src=\"https:\/\/blog.gunlerveisler.gen.tr\/wp-content\/uploads\/2020\/08\/slide9.jpg\" alt=\"\" class=\"wp-image-262\" srcset=\"https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide9.jpg 871w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide9-300x172.jpg 300w, https:\/\/aliyargunes.com.tr\/blog\/wp-content\/uploads\/2020\/08\/slide9-768x439.jpg 768w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><\/figure>\n\n\n\n<p>Notice how the addition node and multiplication nodes how don&#8217;t the operator and value fields.<\/p>\n\n\n\n<p>Define toString() prints the infix expression placing parenthesis only when necessary.<br>Add new math operators: exponentiation, factorial, logarithm, trigonometry.<\/p>\n\n\n\n<p><strong>Summary: A polymorphic solution is often better because:<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211;&gt; new behavior can be added without having the original source code, and<br>&#8211;&gt; Each operation\/concern is separated in a separate file which makes it easy to test\/understand, extend, maintain<br>Whenever you see a switch statement in your code base, that&#8217;s usually a clear sign that polymorphism is begging to be there.<\/p><\/blockquote>\n\n\n\n<p><strong>Repeated Condition<\/strong><\/p>\n\n\n\n<p>When you have the same condition all over the code base.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nabstract class Update {\n\/\/ ...\n}\n\nclass I18NUpdate extends Update {\n\nexecute() { ... }\nrender() { ... }\n\n}\n\nclass NonI18Update extends Update {\n\nexecute() { ... }\nrender() { ... }\n\n}\n\nvoid testExecuteDoA {\n\nUpdate u = new MyI18NUpdate();\nu.execute();\nassertX();\n\n}\n\nvoid testExecuteDoB {\n\nUpdate u = new MyNonI18NUpdate();\nu.execute();\nassertX();\n\n}\n<\/pre><\/div>\n\n\n<p>When you start repeating the if statements over and over again, that&#8217;s a clear sign that what you want there is polymorphism.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass Update {\n\nexecute() {\n\nif (FLAG_il8n_ENABLED) {\n\/\/ do A\n}\nelse {\n\/\/ do B\n}\n}\n\nrender() {\n\nif (FLAG_il8n_ENABLED) {\n\/\/ render A\n}\nelse {\n\/\/ render B\n}\n}\n\n}\n<\/pre><\/div>\n\n\n<p><strong>Move each leg of the conditional to an overriding method in a subclass. Make the original method abstract.<\/strong><\/p>\n\n\n\n<p>From a testing point of view, this is great, because when I instantiate an internationalized subclass, I know exactly what I&#8217;m talking about. It&#8217;s not some flag that got set somewhere else; it&#8217;s a concrete class that I can associate with. It significantly lowers my cognitive load when I think about the test.<\/p>\n\n\n\n<p><strong>Where did the ifs go?<\/strong><\/p>\n\n\n\n<p>You have two piles of objects which does the business logic.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Pile of Objects<br>&#8211;&gt; business logic<\/p><p>Pile of Construction<br>&#8211;&gt; factories<br>&#8211;&gt; builders<br>&#8211;&gt; Provider<\/p><\/blockquote>\n\n\n\n<p>By seperating the objects out into the objects that the business logic and the objects that do contruction, you can basically move your if statement from being inline inside of your code. Move that if statement into the factory. That actually can have great benefits in terms of performance because you don&#8217;t have to make the decision over and over again.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Pile of Objects<br>&#8211;&gt; reponsible for business logic, domain abstraction<\/p><p>Pile of Construction<br>&#8211;&gt; responsible for building object graphs<\/p><\/blockquote>\n\n\n\n<p>Your contruction pile is also where some of the if statements end up because you want to get in the situation where your application behaves differently, not because you have if statements and flags sprinkled all over your code, but it behaves differently because you&#8217;re wired it to get it differently. Because when you can change the behavior of application simply by the way your wire it together differently, you have a lot of possibilities, what you can do at runtime and in terms of compiletime in understanding, in maintainingit and in extending it.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nabstract class Update {\n\/\/ ...\n}\n\nclass I18NUpdate extends Update {\nexecute() { \/\/do A }\nrender() { \/\/do B }\n}\n<\/pre><\/div>\n\n\n<p><strong>This is where if statement happens:<\/strong><\/p>\n\n\n\n<p><strong><em>Construction<\/em><\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass Consumer {\n\nConsumer (Update u) { ... }\n\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass Factory {\n\nConsumer build { \n\nUpdate u = flag_enabled \n? new I18NUpdate()\n: new NonI18NUpdate();\nreturn new Consumer(u);\n  \n}\n}\n<\/pre><\/div>\n\n\n<p>The if statement has moved from being inline in your application to being inside of your factory.<\/p>\n\n\n\n<p><strong>Benefits<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211;&gt; Conditional is localized in one place<br>&#8211;&gt; No more duplication<br>&#8211;&gt; Seperation of responsibilities, and global state<\/p><\/blockquote>\n\n\n\n<p><strong>When to use Polymorphism<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211;&gt; The behavior changes based on state (the example of multiplication &#8211; we had a flag and based on that flag which already was addition or subtraction)<br>&#8211;&gt; The same if statement over and over again (This typically done with flags)<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">ps.<\/h2>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Replace Conditional With Polymorphism &amp; Primitive Obsession | Code Walks 045\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/os6ssw1qylU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Here is some notes which I took from a Google Tech Talks video: When to use Polymorphism if an object should behave differently based on its state If you have to check the same condition in multiple places Use Conditionals &hellip; <a href=\"https:\/\/aliyargunes.com.tr\/blog\/without-an-if-notes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[71,70,72],"class_list":["post-250","post","type-post","status-publish","format-standard","hentry","category-general-concepts","tag-conditional","tag-polymorphism","tag-primitive-obsession"],"_links":{"self":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts\/250"}],"collection":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/comments?post=250"}],"version-history":[{"count":22,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":831,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/posts\/250\/revisions\/831"}],"wp:attachment":[{"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/media?parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/categories?post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aliyargunes.com.tr\/blog\/wp-json\/wp\/v2\/tags?post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}