changing the name of a method/property without changing functionality

W

William H. Burling

i have a nest of vb.vanilla collections.

CollectionofHotelData.item("great Pequot").item("2000").item(22)

The above works. I wrote the code that constructs the nested collections
and i can pull out anything i want within the collections of collections.


However, I want to make my code more readable.
Hence I would like to write it to result in the following:

CollectionofHotelData.Hotel("Great Pequot").Year("2000").SvcPeriod(22)


So I want is to change the vb collection keyword, "item", to something
unique in each collection.(ie: Hotel,Year,SvcPeriod)


What is the smartest way to achieve the above?

I am confused about whether to achieve the result via the use of
"interfaces" (is this only a vb.net feature or is it also in vb.vanilla?)
or through the creation of a new class.

It seems to me that this is a great problem to learn about inheritance,
regardless of whether I achieve the results through classes or interfaces.
I suspect that I could inherit the VB collection class and just include
ONLY the code for the overloaded "item" method (is that correct terminology
for this situation?). I have never "inherited" anything so
I do not know what is really involved yet.

I assume that I would alter the item method (isn't item a method in
vb.vanilla)
like this:

Public Property Get HOtel(VntIndexKey as variant)
set Hotel = mcol(vntindexkey)
End Property

I am not sure if I have to declare mcol as a collection since the base
class
VBcollection already has mcol declared.

I know I have to put the following at the head of the module:
Public Class Collection
Inherits Collection

Also...i am not sure I understand the difference between "shadowing" and
overriding.

Thank you for your help.

Bil
 
J

Jay B. Harlow [MVP - Outlook]

William,
What is the smartest way to achieve the above?
The Rename Method refactoring.

http://www.refactoring.com/catalog/renameMethod.html

One method I have been using lately to achieve the above is to create the
new method, then put the Obsolete attribute on the old method. The compiler
will flag all uses of that method with a warning. I then change each method
to use the new one. Test. Then delete the old method.

Something like:

Public Class HotelCollection
Inherits DictionaryBase

<Obsolete("Use the Hotel property instead")> _
Default Public Readonly Property Item(ByVal name As string) As Hotel
Get
Return DirectCast(me.InnerHashtable(name), Hotel)
End Get
End Property

Public Readonly Property Hotel(ByVal name As String) As Hotel
Get
Return DirectCast(me.InnerHashtable(name), Hotel)
End Get
End Property

End Class

Any use of the Item property will have a compiler warning, as you need to
use the Hotel property instead. You can pass a parameter to the
ObsoleteAttribute that causes an error instead of a warning.
i have a nest of vb.vanilla collections.
By 'vb.vanilla' do you mean Microsoft.VisualBasic.Collection? You may want
to consider using one of the collection classes in System.Collections &
System.Collections.Specialized.

You can even derive from System.Collections.CollectionBase or
System.Collections.DictionaryBase to create a type safe collection.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top