469,919 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,919 developers. It's quick & easy.

VB.NET implementing an interface question

Hi all, when I write the class below

Private Class employee

End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display

Private Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVCO.getPerson
End Function
End Class
The interface defines a single function returning type personDetails.

My question is why is the function declaration in my private class

Public Function getPerson() As personDetails Implements
IVCO.getPerson

and just not

Public Function getPerson() As personDetails

because I already have the "Implements IVF" in the class header. In
other classes I have written, that also implement an interface, I
don't have this "Implements IVCO.getPerson" bit and I'm not sure why,
and if I remove it the compiler complains.

I am running VS2003, .Net runtime 1.1, on a WinXP home computer.

Thank you
Colin
BTW: my interface looks like this and is a separate class/file in my
project.
Public Interface IVF
Function getPerson() As personDetails
End Interface
Nov 20 '05 #1
5 1530
IVCO must be the name of the Module/Class where the definition of the
function is. The IDE will put the stubs in automatically for you. Then you
must implement the interface.

Regards - OHM

Colin McGuire wrote:
Hi all, when I write the class below

Private Class employee

End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display

Private Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVCO.getPerson
End Function
End Class
The interface defines a single function returning type personDetails.

My question is why is the function declaration in my private class

Public Function getPerson() As personDetails Implements
IVCO.getPerson

and just not

Public Function getPerson() As personDetails

because I already have the "Implements IVF" in the class header. In
other classes I have written, that also implement an interface, I
don't have this "Implements IVCO.getPerson" bit and I'm not sure why,
and if I remove it the compiler complains.

I am running VS2003, .Net runtime 1.1, on a WinXP home computer.

Thank you
Colin
BTW: my interface looks like this and is a separate class/file in my
project.
Public Interface IVF
Function getPerson() As personDetails
End Interface


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #2
Sorry that should read.

IVCO must be the name of the Module/Class where the delaration of the
function is.

Regards - OHM#
One Handed Man [ OHM# ] wrote:
IVCO must be the name of the Module/Class where the definition of the
function is. The IDE will put the stubs in automatically for you.
Then you must implement the interface.

Regards - OHM

Colin McGuire wrote:
Hi all, when I write the class below

Private Class employee

End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display

Private Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVCO.getPerson
End Function
End Class
The interface defines a single function returning type personDetails.

My question is why is the function declaration in my private class

Public Function getPerson() As personDetails Implements
IVCO.getPerson

and just not

Public Function getPerson() As personDetails

because I already have the "Implements IVF" in the class header. In
other classes I have written, that also implement an interface, I
don't have this "Implements IVCO.getPerson" bit and I'm not sure why,
and if I remove it the compiler complains.

I am running VS2003, .Net runtime 1.1, on a WinXP home computer.

Thank you
Colin
BTW: my interface looks like this and is a separate class/file in my
project.
Public Interface IVF
Function getPerson() As personDetails
End Interface


Regards - OHM# On**********@BTInternet.com


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #3
* co***********@lycos.co.uk (Colin McGuire) scripsit:
Private Class employee

End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display

Private Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVCO.getPerson
End Function
End Class
The interface defines a single function returning type personDetails.

My question is why is the function declaration in my private class

Public Function getPerson() As personDetails Implements
IVCO.getPerson

and just not

Public Function getPerson() As personDetails

because I already have the "Implements IVF" in the class header. In
other classes I have written, that also implement an interface, I
don't have this "Implements IVCO.getPerson" bit and I'm not sure why,
and if I remove it the compiler complains.


In VB.NET you need to explicitly specify the 'Implements...'. There is
no implicit implementation like in C#. Therefore, in VB.NET, more than
one method can implement a method defined in an interface, and the
method implementing the method of the interface doesn't necessarily have
to have the same name as defined in the interface.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Colin,
In addition to the other comments:

Your example seems to be inconsistent!

Given:
Public Class employee

End Class
Public Interface IVF Function getPerson() As personDetails End Interface

When Employee implements the interface you will get:
Public Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVF.getPerson
End Function
End Class
Your example has "IVCO.getPerson" which would cause a compile error!

As VB.NET requires the Implements statement in the class to signify that the
class implements the interface, plus it needs the Implements clause on each
method that implements a method of the interface. The Implements clause
allows you to rename and/or hide the method from the normal public
"interface" of the class.

For example you can do: Public Class employee
Implements IVF
Protected Function GetThePersonDetails() As personDetails Implements IVF.getPerson
End Function
End Class
Are you perhaps confusing Implements with Inherits? As Inherits does not use
a clause on each method (function, sub, or property).

Hope this helps
Jay

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om... Hi all, when I write the class below

Private Class employee

End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display

Private Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVCO.getPerson
End Function
End Class
The interface defines a single function returning type personDetails.

My question is why is the function declaration in my private class

Public Function getPerson() As personDetails Implements
IVCO.getPerson

and just not

Public Function getPerson() As personDetails

because I already have the "Implements IVF" in the class header. In
other classes I have written, that also implement an interface, I
don't have this "Implements IVCO.getPerson" bit and I'm not sure why,
and if I remove it the compiler complains.

I am running VS2003, .Net runtime 1.1, on a WinXP home computer.

Thank you
Colin
BTW: my interface looks like this and is a separate class/file in my
project.
Public Interface IVF
Function getPerson() As personDetails
End Interface

Nov 20 '05 #5
Jay, Herfried, OHM# thanks for your comments. I am on the right track
now and still learning more, which you will notice by me not posting
so many questions :)

Jay - thanks. The IVCO was a typo when converting my real code into
something a lot simpler for posting.

Thank you all again
Colin

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<ul**************@TK2MSFTNGP09.phx.gbl>...
Colin,
In addition to the other comments:

Your example seems to be inconsistent!

Given:
Public Class employee

End Class


Public Interface IVF
Function getPerson() As personDetails

End Interface

When Employee implements the interface you will get:
Public Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVF.getPerson
End Function
End Class


Your example has "IVCO.getPerson" which would cause a compile error!

As VB.NET requires the Implements statement in the class to signify that the
class implements the interface, plus it needs the Implements clause on each
method that implements a method of the interface. The Implements clause
allows you to rename and/or hide the method from the normal public
"interface" of the class.

For example you can do:
Public Class employee
Implements IVF
Protected Function GetThePersonDetails() As personDetails

Implements
IVF.getPerson
End Function
End Class


Are you perhaps confusing Implements with Inherits? As Inherits does not use
a clause on each method (function, sub, or property).

Hope this helps
Jay

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hi all, when I write the class below

Private Class employee

End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display

Private Class employee
Implements IVF
Public Function getPerson() As personDetails Implements
IVCO.getPerson
End Function
End Class
The interface defines a single function returning type personDetails.

My question is why is the function declaration in my private class

Public Function getPerson() As personDetails Implements
IVCO.getPerson

and just not

Public Function getPerson() As personDetails

because I already have the "Implements IVF" in the class header. In
other classes I have written, that also implement an interface, I
don't have this "Implements IVCO.getPerson" bit and I'm not sure why,
and if I remove it the compiler complains.

I am running VS2003, .Net runtime 1.1, on a WinXP home computer.

Thank you
Colin
BTW: my interface looks like this and is a separate class/file in my
project.
Public Interface IVF
Function getPerson() As personDetails
End Interface

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Martyn Lawson | last post: by
4 posts views Thread by Frank J. Reashore | last post: by
3 posts views Thread by needin4mation | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.