Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overload & Override

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
0
0
GB
I have come across an example in the Wrox book, 'Professional VB.Net 2003' I don't understand.

It describes a way in which a property can be overloaded and overriden at the same time from a base class.

This as a concept is difficult for me to grasp as overloading and overriding are to me, very different.
An 'Overload' in a child class creates another occurrance
on a property with a different parameter list signature.
An 'Override' in a child class creates a property that matches the parameter signature of the base property but defines a completely different set of actions.

How can both you have a property that has both the same parameter signature and a different parameter signauture at the same time?

 
well its not that difficult, think about it.

the original program had a property called "print"

you overridde that property print with one parameter
but you want a second option with two parameters so you are still overriding the print propertie but at the same time you are overloading it because you have two instances of it wich differ from eachother because they have different sets of parameters.

think about it


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Well of course I'd thought about it and I do find it difficult.


With regards to your 'print' property, I think you are looking at the wrong example entirely. I am refering to pages 180 and 181. This deals with a Name property.

Taking the case you describe, I would expect to see one derived class version of 'print' with Override using the same number of parameters and another derived class version of 'print' with Overload so that it can have a different parameter list.

The actual circumstance I am looking at in the derived class looks like this. It has both override and overload at the same time in one definition:-


Public Overloads Overrides Property Name() As String
Get
Return Name(NameTypes.Normal)
End Get

Set(Byval Value As String)
Name(NameTypes.Normal) = Value
End Set
End Property


So its that bit I find hard to understand.
In the book it actually states when "we overload a method we're adding a new method with the same name but a different parameter list. When we override a method we're actually replacing the original method with a new implementation". Therefore an original method with the same parameter list is overriden while an alternative parameter list is overloaded.

I recognise I'm missing something here but I'm not sure your answer is refering to the question I was asking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top