Home All Groups Group Topic Archive Search About

Implementing an interface by relying on base class

Author
6 Jun 2005 8:59 AM
Gareth

Hi,

I'd like to do be able to implement an interface in a derived class by
relying on the base class for some of the members.  For example like
this:

Interface ITest
    Property prpA() As Integer
    Property prpB() As Integer
End Interface

Public MustInherit Class BaseClass
    Public Property prpA() As Integer
        Get
            Return 1
        End Get
        Set(ByVal Value As Integer)

        End Set
    End Property
End Class

Public Class DerivedClass
    Inherits BaseClass
    Implements ITest

    Public Property prpB() As Integer Implements ITest.prpB
        Get
            Return 0
        End Get
        Set(ByVal Value As Integer)

        End Set
    End Property
End Class

But the compiler doesn't recognise prpA as being present in
DerivedClass.  Can anyone tell me how I could get round this, and also
why it should be that this is not allowed?

Thanks,

Gareth
Author
8 Jun 2005 8:25 AM
Schmeusser
Maybe you could use C# as the problem does not exist there

interface IPoint
    {
        // Property signatures:
        int x
        {
            get;
            set;
        }

        int y
        {
            get;
            set;
        }
    }

    class BasePoint
    {
        private int myX;

        // Property implementation:
        public int x
        {
            get
            {
                return myX;
            }

            set
            {
                myX = value;
            }
        }
    }

    class MyPoint : BasePoint, IPoint
    {
        // Fields:
        private int myY;

        // Constructor:
        public MyPoint(int x, int y)
        {
            x = x;
            myY = y;
        }


        public int y
        {
            get
            {
                return myY;
            }
            set
            {
                myY = value;
            }
        }
    }



Show quoteHide quote
"Gareth" wrote:

> Hi,
>
> I'd like to do be able to implement an interface in a derived class by
> relying on the base class for some of the members.  For example like
> this:
>
> Interface ITest
>     Property prpA() As Integer
>     Property prpB() As Integer
> End Interface
>
> Public MustInherit Class BaseClass
>     Public Property prpA() As Integer
>         Get
>             Return 1
>         End Get
>         Set(ByVal Value As Integer)
>
>         End Set
>     End Property
> End Class
>
> Public Class DerivedClass
>     Inherits BaseClass
>     Implements ITest
>
>     Public Property prpB() As Integer Implements ITest.prpB
>         Get
>             Return 0
>         End Get
>         Set(ByVal Value As Integer)
>
>         End Set
>     End Property
> End Class
>
> But the compiler doesn't recognise prpA as being present in
> DerivedClass.  Can anyone tell me how I could get round this, and also
> why it should be that this is not allowed?
>
> Thanks,
>
> Gareth
>
>

Bookmark and Share