[21.1] Should I hide member functions that were public in my base class?
Never, never, never do this. Never. Never!
This is too strong. What do you do when you have no control over the
base class? What do you do when a library (the .NET Framework, for
example) provides a base class that gives you all of the functionality
you need, but has some methods and properties that don't apply to the
implementation you want to provide? Do you:
1. Tell Microsoft that they designed their base class badly, and wait
for them to fix it.
or
2. Tell your boss that you have to build a complete new implementation
of, say, XmlReader because it has five methods that don't apply to the
class you want to build (but otherwise it's a perfect fit),
or
3. Hold you nose, override the methods in question, and throw a
MethodNotSupported exception if they're called in your subclass, or, if
they're not virtual, declare "new" versions of them and do likewise?
If I were to do 1 or 2, I'd be fired.
Now, if I built the base class myself, then you're right: if I'm doing
this sort of nastiness in a subclass then my class hierarchy is wrong
and I really should fix it. In Mark's example below, GiveBirth() really
should be in an interface, called ILiveBirth or something, that all
Mammal classes except Platypus implement. However, as I said, this
assumes that I wrote Mammal and Platypus, and have the luxury (and the
time) to rebuild Mammal appropriately. If Mammal was supplied to me by
an outside party, or I published it to the world and so now can't
change it, then I have little choice but to hold my nose and hack the
subclass.
However, I do agree with Jeff in principle: if you're tempted to do
this then you'd better be ready to defend that decision at code review
time.