Multiple inheritance

levyuk

Well-known member
Joined
Jun 7, 2004
Messages
313
Location
Wales, UK
Programming Experience
3-5
Guys,

I know it's not possible to perform multiple inheritance in .net put I have heard there is a way to fake it. Could anyone give me a simple example. Say for insatance we have these classes

person
student(inherits person)
employee(inherits person)
studentemployee(inherits student & employee)

How could you do this in code. PS it's not home it just came up in a lecture on OO and I was wondering how it could be done in .net

Cheers
Levy
 
in c++.net and c#.net you can do multiple inheritance just not in vb.net

but in this case i dont know of an easy way around that

i would have StudentEmployee inherit Employee then add whatever Student stuff is needed
VB.NET:
Option Explicit On 
Option Strict On

Public Class Person
    Private strName As String

    Friend Property Name() As String
        Get
            Return strName
        End Get
        Set(ByVal Value As String)
            strName = Value
        End Set
    End Property
End Class

Public Class Student
    Inherits Person

    Private intStudentID As Integer
    Friend Property StudentID() As Integer
        Get
            Return intStudentID
        End Get
        Set(ByVal Value As Integer)
            intStudentID = Value
        End Set
    End Property
End Class
as an example
 
Bad ... only C++ supports multiple inheritance, while C# and VB.NET don't. This is valid for all .NET languages ... means .NET platform does not support multiple inheritance. There is a difference between multilevel inheritance and multiple inheritance. With multiple inheritance we can have a subclass that inherits from two classes at the same time. However, through implementing multiple interfaces in VB.NET you can achieve some effects very similar to that of multiple inheritance.

HTH
Regards ;)
 
Back
Top