{"id":33,"date":"2012-02-15T14:25:00","date_gmt":"2012-02-15T14:25:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2012\/02\/15\/favor-composition-over-inheritance\/"},"modified":"2012-02-15T14:25:00","modified_gmt":"2012-02-15T14:25:00","slug":"favor-composition-over-inheritance","status":"publish","type":"post","link":"http:\/\/panahy.nl\/index.php\/2012\/02\/15\/favor-composition-over-inheritance\/","title":{"rendered":"Favor Composition over Inheritance"},"content":{"rendered":"<div>\n<div>Even though you \u201c<i>could\u201d<\/i> solve a problem by inheriting, see if there\u2019s another option that doesn\u2019t require you to inherit and compose your object of other helper object instead.<o:p><\/o:p><\/div>\n<div>The above statement sounded so sophisticated when I read it first, that I wanted to put it in my blog. Yet there is something deep in my heart that tells me: don\u2019t through away your years of experience and achievements gained by reusing objects through inheritance.<o:p><\/o:p><\/div>\n<h2>Original Thought<o:p><\/o:p><\/h2>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\">When 2 classes, let\u2019s say Car and Vehicle implemented as follows:<br \/><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">class<\/span> <span style=\"color: #2b91af;\">Vehicle<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">void<\/span> Drive() <o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ <o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #2b91af;\">Debug<\/span>.WriteLine(<span style=\"color: #a31515;\">&#8220;Vehicle is driving.&#8221;<\/span>);<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">class<\/span> <span style=\"color: #2b91af;\">Car<\/span> : <span style=\"color: #2b91af;\">Vehicle<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">void<\/span> Drive()<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Debug<\/span>.WriteLine(<span style=\"color: #a31515;\">&#8220;Car is driving.&#8221;<\/span>);<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div>By default the new implemented Drive method in the Car class hides the implementation in vehicle for any reference of Car type. So the following instances are expected:<o:p><\/o:p><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Vehicle<\/span> v = <span style=\"color: blue;\">new<\/span> <span style=\"color: #2b91af;\">Vehicle<\/span>();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; v.Drive();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: green;\">\/\/ output : Vehicle is driving.<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Car<\/span> c = <span style=\"color: blue;\">new<\/span> <span style=\"color: #2b91af;\">Car<\/span>();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; c.Drive();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: green;\">\/\/ output : Car is driving.<o:p><\/o:p><\/span><\/span><\/div>\n<div><\/div>\n<div>But the next one might cause unexpected situations when the construction occurs in a method far from calling the drive method.<o:p><\/o:p><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Vehicle<\/span> x = <span style=\"color: blue;\">new<\/span> <span style=\"color: #2b91af;\">Car<\/span>();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; x.Drive();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: green;\">\/\/ output : Vehicle is driving.<o:p><\/o:p><\/span><\/span><\/div>\n<div><\/div>\n<div>The output for the last call (Vehicle x) changes to \u201c<b><span style=\"font-family: 'Courier New'; font-size: 8pt; line-height: 115%;\">Car<\/span><\/b><span style=\"font-family: 'Courier New'; font-size: 8pt; line-height: 115%;\"> is driving.\u201d <\/span>when the <i>Drive<\/i> method in <i>Vehicle<\/i> is defined as <span style=\"color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\">virtual <\/span>and in the Car defined as <span style=\"color: blue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\">override<\/span>.<o:p><\/o:p><\/div>\n<div>Looks like the problem is solved.<o:p><\/o:p><\/div>\n<div>But sometime I have a factory class creating some instances for me and I simply declare my variables and request for an instance:<o:p><\/o:p><\/div>\n<div><span style=\"color: #2b91af; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\">Vehicle<\/span><span style=\"font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\"> x = <span style=\"color: #2b91af;\">Factory<\/span>.GetBMW();<\/span><o:p><\/o:p><\/div>\n<div>This means that the place I use the instance might have no knowledge of how the instance is created and might not even know how they are implementing the Drive method.<o:p><\/o:p><\/div>\n<div>For me, the ideal situation might be when I have a reference to a class of type Vehicle, I like it to drive as Vehicle. And when I want to have a Car that drives as a Car, I will define my reference as a Car. <o:p><\/o:p><\/div>\n<div><span style=\"color: #2b91af; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\">Vehicle<\/span><span style=\"font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\"> x = <span style=\"color: #2b91af;\">Factory<\/span>.GetBMW();<br \/><span style=\"color: #2b91af;\">Car<\/span> y = <span style=\"color: #2b91af;\">Factory<\/span>.GetBMW();<br \/>x.Drive();<br \/>y.Drive();<\/span><o:p><\/o:p><\/div>\n<div>I can see that my point might not be important for BMW factory and they would rather to create a Car that drives the same way, no matter who is driving it.<o:p><\/o:p><\/div>\n<h2>Suggested Solution<o:p><\/o:p><\/h2>\n<div>The Composition over inheritance suggests that Car and vehicle does not inherit from each other. To make sure that they both are sharing functionality, the BMW class needs to implement both interfaces. <o:p><\/o:p><\/div>\n<div>Let\u2019s say that the following code is where we like to achieve:<o:p><\/o:p><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; x.Drive();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: green;\">\/\/ output : Simply driving.<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; (x <span style=\"color: blue;\">as<\/span> <span style=\"color: #2b91af;\">ICar<\/span>).Drive();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: green;\">\/\/ output : Car driving.<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; (x <span style=\"color: blue;\">as<\/span> <span style=\"color: #2b91af;\">IVehicle<\/span>).Drive();&nbsp;&nbsp;&nbsp; <span style=\"color: green;\">\/\/ output : Vehicle driving.<o:p><\/o:p><\/span><\/span><\/div>\n<div><\/div>\n<div>To get there I have introduced three interfaces as follows:<o:p><\/o:p><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">interface<\/span> <span style=\"color: #2b91af;\">IDrivable<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">void<\/span> Drive();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">interface<\/span> <span style=\"color: #2b91af;\">IVehicle<\/span> : <span style=\"color: #2b91af;\">IDrivable<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">void<\/span> Drive();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">public<\/span> <span style=\"color: blue;\">interface<\/span> <span style=\"color: #2b91af;\">ICar<\/span> : <span style=\"color: #2b91af;\">IDrivable<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">void<\/span> Drive();<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div><\/div>\n<div>The BMW needs to implement them as it suites. This implementation has nothing to do with the way they are overloaded. <o:p><\/o:p><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"color: blue; font-family: 'Courier New'; font-size: 10pt;\">public<\/span><span style=\"font-family: 'Courier New'; font-size: 10pt;\"> <span style=\"color: blue;\">class<\/span> <span style=\"color: #2b91af;\">BMW<\/span> : <span style=\"color: #2b91af;\">IVehicle<\/span>, <span style=\"color: #2b91af;\">ICar<o:p><\/o:p><\/span><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">void<\/span> <span style=\"color: #2b91af;\">IVehicle<\/span>.Drive()<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Debug<\/span>.WriteLine(<span style=\"color: #a31515;\">&#8220;Vehicle is driving.&#8221;<\/span>);<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">void<\/span> <span style=\"color: #2b91af;\">ICar<\/span>.Drive()<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Debug<\/span>.WriteLine(<span style=\"color: #a31515;\">&#8220;Car is driving.&#8221;<\/span>);<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue;\">void<\/span> <span style=\"color: #2b91af;\">IDrivable<\/span>.Drive()<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: #2b91af;\">Debug<\/span>.WriteLine(<span style=\"color: #a31515;\">&#8220;Simply driving.&#8221;<\/span>);<o:p><\/o:p><\/span><\/div>\n<div style=\"line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm; text-autospace: none;\"><span style=\"font-family: 'Courier New'; font-size: 10pt;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p><\/o:p><\/span><\/div>\n<div><span style=\"font-family: 'Courier New'; font-size: 10pt; line-height: 115%;\">&nbsp;&nbsp;&nbsp;&nbsp;}<\/span><o:p><\/o:p><\/div>\n<div><\/div>\n<div>Used sources: <a href=\"http:\/\/geekswithblogs.net\/dlussier\/archive\/2008\/01\/15\/118585.aspx\">http:\/\/geekswithblogs.net\/dlussier\/archive\/2008\/01\/15\/118585.aspx<\/a><o:p><\/o:p><\/div>\n<div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Even though you \u201ccould\u201d solve a problem by inheriting, see if there\u2019s another option that doesn\u2019t require you to inherit and compose your object of other helper object instead. The above statement sounded so sophisticated when I read it first, that I wanted to put it in my blog. Yet there is something deep in &hellip; <a href=\"http:\/\/panahy.nl\/index.php\/2012\/02\/15\/favor-composition-over-inheritance\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Favor Composition over Inheritance&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"Even though you \u201ccould\u201d solve a problem by inheriting, see if there\u2019s another option that doesn\u2019t require you to inherit and compose your object of other helper object instead. The above statement sounded so sophisticated when I read it first, that I wanted to put it in my blog. Yet there is something deep in&hellip;","_links":{"self":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/33"}],"collection":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}