Re: Why Overloads needed
From: Lee Silver (LSilver_at_information-concepts.com)
Date: 06/05/04
- Next message: jcrouse: "RE: Speeding up a form load"
- Previous message: jcrouse: "RE: Speeding up a form load"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Why Overloads needed"
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: Why Overloads needed"
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: Why Overloads needed"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 05 Jun 2004 14:07:43 -0400
Jay:
Aha, I think I got it -- the key phrase is "Shadows is used for versioning".
Without Overloads, Shadows would be required; and since neither is implied I
need to specify Overloads.
But this brings up something interesting... In my Base class I have a
non-overloaded overridable property, Item. In my derived class I declare it
Overrides, without Overloads or Shadows, and it compiles just fine. If at some
point in the future I modify Base class to overload Item, won't that break my
derived class?
-- // Lee Silver // Information Concepts Inc. // http://www.information-concepts.com Facilitating the automated conversion of Data into Information since 1982 > Lee, > In addition to the other comments: > > Overloads is needed so the compiler will know if Sub Remove(Object) will be > available via your derived class! > > Consider the following: > > Option Strict On > > Public Class Base > > Public Overridable Sub Remove(ByVal wIndex As Integer) > > End Sub > > Public Overridable Sub Remove(ByVal wValue As Object) > > End Sub > > Public Sub Main() > Dim overlord As New OverloadedBase > overlord.Remove(10) > overlord.Remove("Jay") > > Dim underlord As New ShadowsBase > underlord.Remove(10) > underlord.Remove("Jay") > End Sub > > End Class > > Public Class OverloadedBase > Inherits Base > > Public Overloads Overrides Sub Remove(ByVal wIndex As Integer) > End Sub > > End Class > > > Public Class ShadowsBase > Inherits Base > > Public Overrides Sub Remove(ByVal wIndex As Integer) > End Sub > > End Class > > > The underload.Remove("Jay") method has an error, because you forgot to > include Overloads, so Shadows was implicitly used. Shadows causes > Base.Remove(Object) to be hidden in OverloadedBase set of methods. Without > the Option Strict On, VB.NET will attempt to convert "jay" to an integer at > run time on the underload.Remove("Jay") line. > > Shadows is used for versioning, so methods added to version 2 of classes > don't suddenly cause surprises in classes that were designed for version 1 > of the base class. > > NOTE: Shadows base can be written as: > > Public Class ShadowsBase > Inherits Base > > Public Shadows Overrides Sub Remove(ByVal wIndex As Integer) > End Sub > > End Class > > Which will remove the warning about adding either Shadows or Overloads. > > Hope this helps > Jay >
- Next message: jcrouse: "RE: Speeding up a form load"
- Previous message: jcrouse: "RE: Speeding up a form load"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Why Overloads needed"
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: Why Overloads needed"
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: Why Overloads needed"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|