Marcus,

Rats :)  You've stolen my thunder.  Actually, I won't go as far as to say 
"never," but I agree.  There are places in Squeak that inherit from collections 
or put methods in Object, and it sure looks as though the programmer didn't 
know any better.  In fairness, it might have been intended to minimize the 
chance of runtime errors.  Think about it: by wrongly inheriting from 
OrderedCollection, one is freed from having to delegate its methods (it's not 
correct, but can seem wise to a beginner or expedient an experienced programmer 
with poor tools).  Mess around with the internals of the user interface, and 
sliding a method up the hierarchy can avoid a meltdown.  These things were all 
the more true before the days of exception handling.

By all means, we should fix these things as we find them.

Bill



-----Original Message-----
From: pharo-project-boun...@lists.gforge.inria.fr 
[mailto:pharo-project-boun...@lists.gforge.inria.fr] On Behalf Of Marcus Denker
Sent: Wednesday, February 03, 2010 10:53 AM
To: Pharo-project@lists.gforge.inria.fr
Cc: Laval Jannik
Subject: Re: [Pharo-project] DirectoryEntry does not inherit from 
ArrayedCollection [WAS] Re: [squeak-dev] 3.11 questions


On Feb 3, 2010, at 4:43 PM, Mariano Martinez Peck wrote:

> 
> 
> On Wed, Feb 3, 2010 at 4:34 PM, Chris Muller <asquea...@gmail.com> wrote:
> 
> 4) I have refactored DirectoryEntry to no longer inherit from 
> ArrayedCollection.  Is this an improvement with any community 
> interest?
> 
> Do you think this is interesting ?   What are the benefits of such change ? 
> 
> Jannik: do we kill a cycle dependency or something with this change ?
> 

You should never inherit from collections. The problem is that with this, you 
are depending on the internal working of the collection.

Especially objects that model a domain object (like a Directory related thing) 
should *never* inherit from a collection. Only if you need a special *kind* of 
collection (technically), it might be interesting to do a subclass of a 
collection (see MethodDictionary).

If you need a collection, you *use* a collection.  (you put a standard 
collection as an instance var).

It's very tempting to use inheritance to aquire behavior. But in most cases, it 
is wrong to use it.

You can see this abuse of inheritance very often in Squeak... e.g. Scanner is 
the superclass of Parser, there are subclasses of SystemWindow (!!), things 
like that. Bad.


        Marcus

--
Marcus Denker  -- http://www.marcusdenker.de INRIA Lille -- Nord Europe. Team 
RMoD.


_______________________________________________
Pharo-project mailing list
Pharo-project@lists.gforge.inria.fr
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
Pharo-project@lists.gforge.inria.fr
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to