"thechaosengine"
<sh856531@microsofts_free_email_service.com> wrote:
Hi all,
Is there a way to hide a member in a subclass that has been inherited from a
base class?
Lets leave aside any issues regarding whether its a good idea for a moment.
Here's an example similar to what I'm thinking about.
Lets suppose I make a class called RoleCollection.
RoleCollection inherits and extends the functionality of ArrayList.
ArrayList implements a public method called RemoveAt().
I may want to guard against the user of my base class depending on that
method. Maybe i can't be arsed implementing it and just want to hide the
fact that it exists. I could return an OperationNotImplementedException or
something but I'm wondering if its possible to do method hiding.
Ok. Now you can flame me on what a bad idea it is.
Let the flaming scorn begin
tce
What always amazes me is the number of people who claim to
practice OOP and yet have not heard of the Liskov
Substitution Principle (1988):
http://c2.com/cgi/wiki?LiskovSubstitutionPrinciple http://www.objectmentor.com/resources/articles/lsp.pdf
Its paraphrased as "subtypes must be substitutable for their
basetype."
That being said, hiding inherited members is simply absurd.
The fact that the practice all of a sudden seems useful is
usually indicative of overuse of inheritance - to counteract
that:
- Refactor the inherited "interface" into two or more actual
interfaces.
- implement only those interfaces required in the new type
and reuse the supertype through containment and delegation.
See also:
Uses and Abuses of Inheritance
http://www.gotw.ca/publications/mill06.htm http://www.gotw.ca/publications/mill07.htm