
{"id":2012,"date":"2016-06-14T22:24:33","date_gmt":"2016-06-15T02:24:33","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=2012"},"modified":"2016-06-14T22:24:33","modified_gmt":"2016-06-15T02:24:33","slug":"oop-gone-wild","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=2012","title":{"rendered":"OOP Gone Wild"},"content":{"rendered":"<p>In a piece of code I inherited from some smart, well meaning, but a little disorganized East European consultants, I found the following class hierarchy:<\/p>\n<p><code><\/p>\n<pre>RestClient (abstract)\n   JsonClient (abstract)\n      XyzClient*\n          SessionClient\n      ApiClient<\/pre>\n<p><\/code><br \/>\n<small>* XYZ is our proprietary service. The name was changed to protect the innocent.<\/small><\/p>\n<p>It&#8217;s been a while since I&#8217;ve seen a class hierarchy 4 levels deep, especially with concrete classes inheriting from other concrete classes. Somehow these days people prefer composition. None of the abstract classes contain any abstract methods, just protected virtuals <b>with implementations<\/b>. So why are those classes abstract then?<\/p>\n<p>I believe someone long time ago established that inheriting concrete classes from other concrete classes is a bad idea, but I already forget who, and I hope his advice was not based on the C++ &#8220;slicing&#8221; phenomenon.<\/p>\n<p>The separation of responsibilities between the classes is somewhat unclear. <code>ApiClient<\/code> is described as &#8220;Base client class for REST API clients that manages XYZ session&#8221;. I wonder then what&#8217;s the difference between it and the <code>SessionClient<\/code>. Anyhow, it probably does not matter, since <code>ApiClient<\/code> is not used anywhere \ud83d\ude42 In fact, deeper investigation shows that <b>all of these classes are dead code<\/b>. We do have a place that makes a REST call and parses JSON, but it does not use any of those classes, and neither does any other piece of callable code.<\/p>\n<p>Don&#8217;t do this at home, folks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a piece of code I inherited from some smart, well meaning, but a little disorganized East European consultants, I found the following class hierarchy: RestClient (abstract) JsonClient (abstract) XyzClient* <a href=\"https:\/\/ikriv.com\/blog\/?p=2012\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[5],"tags":[],"class_list":["entry","author-ikriv","post-2012","post","type-post","status-publish","format-standard","category-dev"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2012"}],"version-history":[{"count":0,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2012\/revisions"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}