Inheritance question / problem-Collection of common programming errors
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) {
md.draw(canvas);
super.dispatchDraw(canvas);
}
}
class MyRelativeLayout extends RelativeLayout {
// as above
}
Although I still have two classes that extend, but I’m not duplicating the code that was duplicated before which was what I wanted to achieve.