Edit parent in inheritance chain while maintaining base parents \ children

I have the following .Net inheritance chains:

  • Control -> ButtonBase -> Button
  • Control -> Label
  • Control -> ScrollableControl -> Panel

I want to edit the Control Class, but want to use the .Net children of this parent.

I am imagining this to look something like this?

    public class TouchControl : Control     {         public event MouseEventHandler TouchDown, TouchUp;         protected override void WndProc(ref Message m)          {             if(m == a)             {TouchDown(Object, MouseEventArgs);}             else if (m == b)             {TouchUp(Object, MouseEventArgs);}         }     }         public class TouchButtonBase : TouchControl     {         // Inherits from TouchControl but implements ButtonBase Class     }      public class TouchButton : TouchButtonBase     {         // Inherits TouchButtonBase but implements Button Class      }      public class TouchLabel: TouchControl     {         // Inherits TouchControl but implements Label Class     } 

What is the best way to accomplish this?

My current approach violates the DRY principle and I would like to fix this:

    public class TouchPanel : Panel     {         protected override void WndProc(ref Message m)          {             //Repeated functionality         }     }      public class TouchButton  : Button     {         protected override void WndProc(ref Message m)         {             //Repeated functionality         }     }      public class TouchPictureBox : PictureBox     {         protected override void WndProc(ref Message m)         {             //Repeated functionality         }     }      public class TouchLabel: Label     {         protected override void WndProc(ref Message m)         {             //Repeated functionality         }     } 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.