473,395 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can a base class implement a method on an interface for me?

I rarely have the pleasure of working in VB.NET so forgive my
ignorance, but what I'm trying to do is very easy in C# and I'm
wondering whether a similar thing is possible in VB.NET.

I have a class MySuperForm

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In c# that would compile, but in VB.NET I need to declare which method
implements Show() but I can't because the method doesn't belong to me.
It belongs to Form.

The only workaround I have found is to shadow the Sub

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
Public Shadows Sub Show() Implements IMySuperForm.Show
MyBase.Show()
End Sub
End Class

Is this the only way to achieve this?

Nov 16 '06 #1
3 1200

MrAnon wrote:
I rarely have the pleasure of working in VB.NET so forgive my
ignorance, but what I'm trying to do is very easy in C# and I'm
wondering whether a similar thing is possible in VB.NET.

I have a class MySuperForm

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In c# that would compile, but in VB.NET I need to declare which method
implements Show() but I can't because the method doesn't belong to me.
It belongs to Form.

The only workaround I have found is to shadow the Sub

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
Public Shadows Sub Show() Implements IMySuperForm.Show
MyBase.Show()
End Sub
End Class

Is this the only way to achieve this?
I think so... does shadowing the sub cause any serious problems?

Nov 16 '06 #2
"MrAnon" <jo********@gmail.comwrote in news:1163676877.010944.75070
@m73g2000cwd.googlegroups.com:
I rarely have the pleasure of working in VB.NET so forgive my
ignorance, but what I'm trying to do is very easy in C# and I'm
wondering whether a similar thing is possible in VB.NET.
Declare the class as MustInherit.
Nov 16 '06 #3
MrAnon wrote:
I have a class MySuperForm

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm
End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In c# that would compile, but in VB.NET I need to declare which method
implements Show() but I can't because the method doesn't belong to me.
It belongs to Form.
Cut and pasted into VB'2003 and, after taking out the '>'s and pressing
Enter in a few choice places, the IDE gave me this ...

Public Class MySuperForm
Inherits Form '' Yup, System.Windows.Forms.Form
Implements IMySuperForm

' BINGO!
Public Sub Show1() Implements IMySuperForm.Show

End Sub

End Class

Public Interface IMySuperForm
Sub Show()
End Interface

In fact, Show1 doesn't even have to be Public, if you don't want it to be.

HTH,
Phill W.
Nov 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alexey Klimkin | last post by:
Hello! Is it possible in python to replace base class with another one? Assume an example: class A: def f(self): print 'A' class B(A): def f(self):
4
by: Néstor Marcel Sánchez Ahumada | last post by:
In a method declaration the 'sealed' keyword must be used with the 'override' keyword to avoid further overriding. Thus it can't be used in base classes. Why? This would be a good enhancement for...
4
by: Rachel Devons | last post by:
All, I'm struggling with an OOP concept. Let me try to define what I'm wanting by using some classic examples. Let's say that I have classes called Square & Circle that derive from class...
15
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } ...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
2
by: Oenone | last post by:
I could use a little advice to help prevent me making a possible mess of a project. :) In VB6, I once created a project that exposed a public interface class. I then Implemented this in various...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
2
by: Kevin Frey | last post by:
In a derived class I am trying to redefine the implementation of a interface method defined in a base class - the base class interface method was not declared virtual. I have yet to actually...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.