Because inheritance never happens by accident.  Inheritance is one of the
hardest coding techniques to get right.  It is almost always subject to the
rule of reuse: code is not genuinely reusable until you are actually using
it in at least two different scenarios, preferably more.

If you look at inheritance success stories, you typically tend to find that
the best examples are ones where lots and lots of derived classes have been
created.  For example, take the System.Windows.Forms.Control class, one of
my favourite classes, and undoubtedly a class which exploits inheritance
very successfully.  How many classes had been created that derive from this
before it saw the light of day?  I don't know the figure, but if you look at
the ones that actually made it into .NET framework for the first release,
you can see that there were quite a lot.

I would bet money that the Control class we have today is quite
significantly different from the very first design for this class within
Microsoft.  (And it probably would have been more so had it not been for the
experience the team had gained with WFC - I gather there was some continuity
from the J++ UI framework team and the Windows Forms team.)

Every time I've used inheritance, I've found that it has been the result of
a refactoring transformation. I think I have always changed the base class
in order to get it working best.  It is extremely unusual to design a base
class 'ahead' - you only discover what makes a good base class for any
particular application when you try to use your existing class as a base
class and find out what is wrong with it.


I'm increasingly coming to the conclusion that classes should be sealed by
default.


--
Ian Griffiths
DevelopMentor

----- Original Message -----
From: "Jesse Liberty" <[EMAIL PROTECTED]>


> Okay, I've been thinking about this for 2 years, and maybe it is lack of
> imagination. Why would you ever declare a class to be sealed? What is the
> design advantage?  It seems to me that you are almost certainly going to
be
> wrong, sooner or later someone will want to specialize your class.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to