-
Reimplementing interfaces in vb
I've been trying to reimplement an interface in vb, but the compiler won't
let me.
Class Base implements ITest. Class Derived inherits from Class Base and
tries to implement ITest, but can't.
I'd like to know if this is because I've got improper scoping or visibility
issues or if it simply is not possible in vb.
I'm puzzled because C# let's me do this without a problem. And this is so
fundamental that I'd be really surprised if this feature was not in both
languages.
-
Re: Reimplementing interfaces in vb
I haven't been able to find a way to reimplement an interface in from a derived
class VB.NET (beta 2) either.
Of course, you do have several options such as using interface implementation
throughout instead of inheritance and reimplementation (yuck... in some cases).
However, I did find that if you make the implementing member friend or public
in the base class, you can override it in the derived class, and that override
will be used as the implementation for the interface in the derived class.
In other words:
Option Strict On
Public Interface ITest
Function Foo() As Integer
End Interface
Public Class TestBase
Implements ITest
Public Function Bar() As Integer
Return 100
End Function
Friend Overridable Function Foo() As Integer Implements ITest.Foo
Return 1
End Function
End Class
Public Class TestDerive
Inherits TestBase
Friend Overrides Function Foo() As Integer
Return 2
End Function
End Class
I haven't thought too much about this while working with VB.NET so far, so
I'll have to dig into the docs a bit more to see how it's supposed to work,
and why there is a limitation in reimplementation of a common interface on
inherited classes.
-Rob
"Ed Pinto" <ed.pinto@eds.com> wrote:
>
>I've been trying to reimplement an interface in vb, but the compiler won't
>let me.
>
>Class Base implements ITest. Class Derived inherits from Class Base and
>tries to implement ITest, but can't.
>
>I'd like to know if this is because I've got improper scoping or visibility
>issues or if it simply is not possible in vb.
>
>I'm puzzled because C# let's me do this without a problem. And this is
so
>fundamental that I'd be really surprised if this feature was not in both
>languages.
-
Re: Reimplementing interfaces in vb
Thanks Rob. I've been using that technique where appropriate. I guess the
big problem I'm facing is that I don't have control over the all my base
classes, some of them are SDK. Microsoft does. I can't override their implementations
because the scope isn't right.... C# looks like my only option.
>I haven't been able to find a way to reimplement an interface in from a
derived
>class VB.NET (beta 2) either.
>
>Of course, you do have several options such as using interface implementation
>throughout instead of inheritance and reimplementation (yuck... in some
cases).
>However, I did find that if you make the implementing member friend or public
>in the base class, you can override it in the derived class, and that override
>will be used as the implementation for the interface in the derived class.
>
>In other words:
>Option Strict On
>
>Public Interface ITest
> Function Foo() As Integer
>End Interface
>
>Public Class TestBase
> Implements ITest
>
> Public Function Bar() As Integer
> Return 100
> End Function
>
> Friend Overridable Function Foo() As Integer Implements ITest.Foo
> Return 1
> End Function
>End Class
>
>Public Class TestDerive
> Inherits TestBase
>
> Friend Overrides Function Foo() As Integer
> Return 2
> End Function
>End Class
>
>
>I haven't thought too much about this while working with VB.NET so far,
so
>I'll have to dig into the docs a bit more to see how it's supposed to work,
>and why there is a limitation in reimplementation of a common interface
on
>inherited classes.
>
>-Rob
>
>
>"Ed Pinto" <ed.pinto@eds.com> wrote:
>>
>>I've been trying to reimplement an interface in vb, but the compiler won't
>>let me.
>>
>>Class Base implements ITest. Class Derived inherits from Class Base and
>>tries to implement ITest, but can't.
>>
>>I'd like to know if this is because I've got improper scoping or visibility
>>issues or if it simply is not possible in vb.
>>
>>I'm puzzled because C# let's me do this without a problem. And this is
>so
>>fundamental that I'd be really surprised if this feature was not in both
>>languages.
>
-
Re: Reimplementing interfaces in vb
You can also look into Shadowing, although I'm not sure how useful it will
be in the context of implementing an interface.
I'm hoping one of the MS guys will pop in and tell me I'm wrong and there
is a way to do what we're talking about. Either that or tell me why we can't

-Rob
"Ed Pinto" <ed.pinto@eds.com> wrote:
>
>
>Thanks Rob. I've been using that technique where appropriate. I guess
the
>big problem I'm facing is that I don't have control over the all my base
>classes, some of them are SDK. Microsoft does. I can't override their
implementations
>because the scope isn't right.... C# looks like my only option.
>
>>I haven't been able to find a way to reimplement an interface in from a
>derived
>>class VB.NET (beta 2) either.
>>
>>Of course, you do have several options such as using interface implementation
>>throughout instead of inheritance and reimplementation (yuck... in some
>cases).
>>However, I did find that if you make the implementing member friend or
public
>>in the base class, you can override it in the derived class, and that override
>>will be used as the implementation for the interface in the derived class.
>>
>>In other words:
>>Option Strict On
>>
>>Public Interface ITest
>> Function Foo() As Integer
>>End Interface
>>
>>Public Class TestBase
>> Implements ITest
>>
>> Public Function Bar() As Integer
>> Return 100
>> End Function
>>
>> Friend Overridable Function Foo() As Integer Implements ITest.Foo
>> Return 1
>> End Function
>>End Class
>>
>>Public Class TestDerive
>> Inherits TestBase
>>
>> Friend Overrides Function Foo() As Integer
>> Return 2
>> End Function
>>End Class
>>
>>
>>I haven't thought too much about this while working with VB.NET so far,
>so
>>I'll have to dig into the docs a bit more to see how it's supposed to work,
>>and why there is a limitation in reimplementation of a common interface
>on
>>inherited classes.
>>
>>-Rob
>>
>>
>>"Ed Pinto" <ed.pinto@eds.com> wrote:
>>>
>>>I've been trying to reimplement an interface in vb, but the compiler won't
>>>let me.
>>>
>>>Class Base implements ITest. Class Derived inherits from Class Base and
>>>tries to implement ITest, but can't.
>>>
>>>I'd like to know if this is because I've got improper scoping or visibility
>>>issues or if it simply is not possible in vb.
>>>
>>>I'm puzzled because C# let's me do this without a problem. And this is
>>so
>>>fundamental that I'd be really surprised if this feature was not in both
>>>languages.
>>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks