473,406 Members | 2,620 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,406 software developers and data experts.

Vb.NET Interface implementation

Guy
Hi

i have a base class (marked 'MustInherit') with a public property called IsValid and a public event called Vali
i have a class (lets call it 'Client') that inherits this base class
so the Client class now has a public event called valid and a public property called IsVali

the client class implements an interface called IListEditorItem, this interface declares two things... (can you guess?

a public event called Vali
and a public property called IsVali

The client obviously has these already (from the base class), but vb.net still says it doesnt have them as the implements keyword must be used and mapped to the corresponding methods etc.

C# would pick this up automatically (as it maps by name for interfaces), how do i get round this issue in vb.net
do i have to write another property called IsValid2 which returns the base class property and implements the interface property
or is there a way i can get the interface to know that the property is already there in the base class

Nov 20 '05 #1
4 6971
"Guy" <gu*@nospam.hcs.com> schrieb
Hi,

i have a base class (marked 'MustInherit') with a public property
called IsValid and a public event called Valid i have a class (lets
call it 'Client') that inherits this base class. so the Client class
now has a public event called valid and a public property called
IsValid

the client class implements an interface called IListEditorItem, this
interface declares two things... (can you guess?)

a public event called Valid
and a public property called IsValid

The client obviously has these already (from the base class), but
vb.net still says it doesnt have them as the implements keyword must
be used and mapped to the corresponding methods etc..
No, unless the base class implements the interface, but it doesn't.
C# would pick this up automatically (as it maps by name for
interfaces), how do i get round this issue in vb.net? do i have to
write another property called IsValid2 which returns the base class
property and implements the interface property? or is there a way i
can get the interface to know that the property is already there in
the base class?


In VB.NET you are free in naming the members implementing the Interface
members. You must use the Implements keyword to "connect" the class member
to the interface member. Consequently it must be placed in the derived
class, and the derived class must call the base members. I hope I'm not
wrong...
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Guy,
In addition to Armin's comments (which are correct Armin).
C# would pick this up automatically (as it maps by name for interfaces), how do i get round this issue in vb.net?
As Armin stated, All members of an interface must be implemented (via
Implements keyword) in the current class.
do i have to write another property called IsValid2 which returns the base class property and implements the interface property?
Yes, Normally what I do is something like:

Private Property IListEditorItem_IsValid() as Boolean Implements
IListEditorItem.IsValid
Get
Return MyBase.IsValid
End Get
Set(ByVal value As Boolean)
MyBase.IsValid = value
End Set
End Property
Unfortunately the event is going to give you problems! I'm really not sure
of any way to accurately implement it...

Have you considered implementing the interface in the base class instead of
the derived class?

Hope this helps
Jay

"Guy" <gu*@nospam.hcs.com> wrote in message
news:C3**********************************@microsof t.com... Hi,

i have a base class (marked 'MustInherit') with a public property called IsValid and a public event called Valid i have a class (lets call it 'Client') that inherits this base class.
so the Client class now has a public event called valid and a public property called IsValid
the client class implements an interface called IListEditorItem, this interface declares two things... (can you guess?)
a public event called Valid
and a public property called IsValid

The client obviously has these already (from the base class), but vb.net still says it doesnt have them as the implements keyword must be used and
mapped to the corresponding methods etc..
C# would pick this up automatically (as it maps by name for interfaces), how do i get round this issue in vb.net? do i have to write another property called IsValid2 which returns the base class property and implements the interface property? or is there a way i can get the interface to know that the property is already there in the base class?

Nov 20 '05 #3
Hi,

Thanks for post in the community.
I am researching the issue, if I have any new information I will update
with you ASAP.

Have a nice day.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #4
Hi,

Thanks for your quickly reply!

It seems that VB.NET will not do the same the thing as the C#.
For a workaround ,you may try the code below.
Module Module1
Public Interface IListEditorItem
Property IsValid() As Boolean
Event Valid()
End Interface
Public MustInherit Class BaseClass
Dim bVal As Boolean
Public Property IsValid() As Boolean
Get
Return bVal
End Get
Set(ByVal Value As Boolean)
bVal = Value
End Set
End Property
Public Event Valid()
Public Sub Fired()
RaiseEvent Valid()
End Sub
End Class
Public Class Client
Inherits BaseClass
Implements IListEditorItem
Public Shadows Property IsValid() As Boolean Implements
IListEditorItem.IsValid
Get
Return MyBase.IsValid
End Get
Set(ByVal Value As Boolean)
MyBase.IsValid = Value
End Set
End Property
Public Shadows Event Valid() Implements IListEditorItem.Valid
Public Shadows Sub Fired()
RaiseEvent Valid()
End Sub
End Class
Public Sub Test()
Console.WriteLine("Hello")
End Sub
Public Sub Main()
Dim o As New Client
AddHandler o.Valid, AddressOf Test
o.Fired()
End Sub
End Module

If you have any concern on this issue,please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

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

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
3
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
3
by: John Underwood | last post by:
Hi.. I was looking at interface, and I have a example in the docs i'll paste below.. I'm not grasping what you would gain by using a interface, does any one have a brief description of their...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
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. ...
6
by: Ricky W. Hunt | last post by:
It's dawning on my a lot of my problems with VB.NET is I'm still approaching it in the same way I've programmed since the late 70's. I've always been very structured, flow-charted everything, used...
8
by: Gregory | last post by:
I have a question about using STL containers in C++ class public interface. Lets say that I want to return some container from class method or accept class method parameter as some container. For...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.