New syntax to map interface members to the base class
Explicit interface implementation in VB makes the code much better readable and maintainable than C# code with its implicit (i.e. hidden/secret) interface implementation.
It is one of the main advantages of VB over C#.
However there is one drawback: If a class implements an interface, all interface members have to be implemented directly in that class.
There is no way in VB to map an interface member to a member of the implementing classe's base class.
In C# this works implicitly without any extra code. In VB, of course, we want to maintain an explicit way to achieve it.
A workaround exits in VB, but it involves an extra method call.
Today (explicit call to the base class):
Public Override Sub Foo() Implements IFace.Foo
Future improvement (direct mapping to the base class, no End Sub, Overrides or Shadows allowed):
Public Sub MyBase.Foo() Implements IFace.Foo
Future improvement, alternative with a new keyword:
Public Sub Foo() Implements IFace.Foo MapsToBase
Thanks for the suggestion. We’re moving language design to GitHub. Please feel free to refile at https://github.com/dotnet/vblang if this suggestion is still something you advocate.
VB team, please find a solution for this.
Mark Hurd commented
A further extension to the same idea:
Suppose you had a Partial Class implementing the interface, then it could make sense to have:
Public Sub MyClass.Bar() Implements IFace.Foo
BTW I've copied the "Public" from the existing example. I'd guess the best option here would be nothing or Partial to signify Bar must or doesn't have to exist respectively. (I assume the former to be the case.)
They way interfaces are used in VB is clearly one of the top reasons to prefer VB over C# (which only offers the horror of implicit interface implementation).
This suggestion would fill a gap in VB's interface system.
Great idea! This would complete the handling of interfaces.