{"id":4849,"date":"2014-03-30T16:06:24","date_gmt":"2014-03-30T16:06:24","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/inheritance-question-problem-collection-of-common-programming-errors\/"},"modified":"2014-03-30T16:06:24","modified_gmt":"2014-03-30T16:06:24","slug":"inheritance-question-problem-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/inheritance-question-problem-collection-of-common-programming-errors\/","title":{"rendered":"Inheritance question \/ problem-Collection of common programming errors"},"content":{"rendered":"<p>I used delegation, although somewhat differently. The only overloaded method I have in my class was an overloaded dispatchDraw. So I moved it to a different class and included an instance of it in each of the classes that extend.<\/p>\n<pre><code> class MyLinearLayout extends LinearLayout {\n        MyDraw md = new MyDraw();\n\n        @Override\n        protected void dispatchDraw(Canvas canvas) {    \n            md.draw(canvas);\n            super.dispatchDraw(canvas);\n        }\n }\n\n class MyRelativeLayout extends RelativeLayout {\n      \/\/    as above\n }\n<\/code><\/pre>\n<p>Although I still have two classes that extend, but I&#8217;m not duplicating the code that was duplicated before which was what I wanted to achieve.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I used delegation, although somewhat differently. The only overloaded method I have in my class was an overloaded dispatchDraw. So I moved it to a different class and included an instance of it in each of the classes that extend. class MyLinearLayout extends LinearLayout { MyDraw md = new MyDraw(); @Override protected void dispatchDraw(Canvas canvas) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4849","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4849"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4849\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}