Larry,
Its a matter of perspective.
Looks like Shadow is a "feature" I could do without. Seems to pretty much
eliminates the possibility for guaranteeing the encapsulation of code in a
base class, right?
Wrong! :-|
The way I view it guarantees the encapsulation of code in both the base &
the derived classes! Calling the method on a variable of the derived class
will call the code that is encapsulated in the derived class, calling the
method on a variable of the base class (with a derived object) will call the
code that is encapsulated in the base class!
In other words every place you need to ensure that you are calling the base
version use a base variable! Which is then dependant of the actual type of
object you are dealing with!
For example:
Public Class Base
Public Sub ImportantMethod()
End Class
Public Class Derived : Inherits Base
Public Shadows Sub ImporantMethod()
End Class
Dim anObject As Base = New Derived
anObject.ImportantMethod()
In the above Base.ImportantMethod is called guaranteed! Granted it sounds
like you are using:
Dim anObject As Derived = New Derived
anObject.ImportantMethod()
Which ensures that the Derived.ImportantMethod is called, which I hope you
realize is equally important!!!! Especially when I defined
Derived.ImportantMethod in version 1 of my project, then
Base.ImportantMethod got defined in version 2 of my project, and changing
Derived.ImportantMethod will not be covered by your financial backers even
with Refactoring (
http://www.refactoring.com).
I get the impression you see Derived.ImportantMethod as a clever ploy your
junior programmers can use to circumnavigate you base class design. This is
where code reviews are useful, using automated tools if possible, one of the
many Code Critics available, would identify it and you can deal with it at
that level, unless this instance falls into the versioning issue in which
case you can keep the Shadows.
Of course in your code review, you could just open the project & do a find
in files for "Shadows" instead of purchasing a Code Critic, however a Code
Critic can ensure other standards are adhered to.
Hope this helps
Jay