Right now I have a base class for my pages which inherits System.Web.UI.Page and another base class for my usercontrols which inherits System.Web.UI.UserControl, these classes contains the same methods. Since C# doesn’t support multiple inheritance I can’t combine the two classes into one that inherits both Page and UserControl.
What would be the best way to keep the functionality in the two base classes but have the implementation of these methods in only one place?
I’m thinking of making a interface and let the two base classes call a third class that contains the implementation of the interface. Is there any better way so that when I add a new method I don’t have to do it in three places (even though the implementation is only in the third class).
If you are using C# 3.0, you can provide your helper methods as extension methods for the
System.Web.UI.Controlclass, of which bothSystem.Web.UI.PageandSystem.Web.UI.UserControlclasses derive.In the
PageorUserControl: