Versioning

 <  Day Day Up  >  

Many applications and class libraries go through multiple release cycles during their lifetimes. When you are upgrading an application or library, it is not uncommon to add functionality in the form of new types and type members. When you are adding new types and type members , though, inheritance can cause a problem. For example, if version 1.0 of a class library contains the following:

 Class Base   Sub S1()     ...   End Sub End Class 

and version 2.0 adds a new method, as follows :

 Class Base   Sub S1()     ...   End Sub   Sub S2()     ...   End Sub End Class 

then any class that derives from Base and defines its own member, S2 , will break when compiled against version 2.0. To solve this problem, the Shadows and Overloads keywords can be used to allow a derived member to hide base members. The Shadows keyword causes a derived member to hide all base members with the same name ; the Overloads keyword causes a derived member to hide only the base members with the same set of parameters. Shadows is the default because it protects implicitly against all changes, but Overloads is useful when a derived type does not wish to hide all the base members. For example:

 Class Base   Sub WriteLine(ByVal i As Integer)     ...   End Sub   Sub Input()     ...   End Sub End Class Class Derived   Inherits Base   Overloads Sub WriteLine(ByVal d As Double)     ...   End Sub   Shadows Sub Input()     ...   End Sub End Class 

In the case of WriteLine , the derived class is augmenting the list of methods ; in the case of Input , it is hiding all other implementations .

 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net