tags:

views:

21

answers:

2

Hi all,

I need to add shared functionality to both Forms and UserControls. Since multiple inheritance isn't supported in .net I wonder how I best tackle this?

The shared functionality is a dictionary that is filled by the form or usercontrol and then processed.

Regards

+1  A: 

Instead of having the Forms & UserControls inherit from a base class can you encapsulate the logic inside of a self contained object so that each form will new up? Then you can limit in the base class just the instantion and interaction with this object which hopefuly is minimal so having it done twice isn't a big deal.

JoshBerke
Heh, that's basically what I said, but in code. It probably would have been faster to write that out :D
McKay
sounds like a good approach. Thanks
Tarscher
+3  A: 
public class SharedFunctionality
{
    public void ImportantToCallThisOnLoad();
}

public class MyForm : Form
{
    SharedFunctionality mySharedFunctionality = new SharedFunctionality();

    public void OnLoad()
    {
        mySharedFunctionality.ImportantToCallThisOnLoad();
    }
}

public class MyControl : Control
{
    SharedFunctionality mySharedFunctionality = new SharedFunctionality();

    public void OnLoad()
    {
        mySharedFunctionality.ImportantToCallThisOnLoad();
    }
}
McKay