Since you (seem) to want to use multiple inheritance to solve code reuse
issues, not the substitution principle, why not favor "composition over
inheritance"? Build up a single common code class (using generics if
necessary), and expose it as a property off your inherited controls. If
you want to be able to treat them the same, implement an interface.

Public Interface ICommonCode(Of T as WebControl)
        ReadOnly Property CommonCode as CommonCode(Of T)
End Interface

Public Class CommonCode(Of T as WebControl)
        ' Common properties
        ' Common methods
End Class

Public Class MyLabel
        Inherits Label
        Implements ICommonCode(Of Label)

        Public ReadOnly Property CommonCode as CommonCode(Of Label)
Implements ICommonCode(Of Label).CommonCode
                Get
                        Return _commonCode
                End Get
        End Property
End Class

--Mark Brackett

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Jonathan
Heizer
Sent: Thursday, February 15, 2007 8:34 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Inheritance/Generic Problem

Hey all,

I am trying to reuse a bunch of Class members, properties, and functions
that are shared across multiple classes.  Each of these classes already
inherit form a web control so I can not create a base class supporting
the
function since .Net does not support multiple inheritance.  Right now
each
Inherited class has a complete copy of this code that makes it hard to
make
changes to it.

So invision...
MyControl1--\                   /---BaseControl1
MyControl2--->Common Code Class<----BaseControl2
MyControl3--/                   \---BaseControl3

What I really need is multiple inheritance...

Public Class MyLabel
        Inherits System.Web.UI.WebControls.Label)
        Inherits MyCommonStuff

End Class

Since so many of these are shared properties and members using basic
interfaces would not really save that much code space.  What I was
trying to
do is mix in generics and do something along these lines...

Public Class MyBaseControl(Of t)
        Inherits t

        Class members...
        Functions...
        Properties...
End Class

Public Class MyLabel
    Inherits MyBaseControl(Of System.Web.UI.WebControls.Label)

End Class

Public Class MyTextbox
    Inherits MyBaseControl(Of System.Web.UI.WebControls.Textbox)

End Class

So what I need is to somehow make my intermediate class inherit the base
control of my choice at runtime based on the type passed through the
generic.  Is anything like this possible?  I have not had any luck so
far.

Thanks for any help,

Jon

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to