Evilness object oriented approach in Morph

Julian Fitzell julian at beta4.com
Wed Jan 25 06:55:08 UTC 2006

Not true.  If a class has *public* accessor methods, it allows anyone to 
know (and even change!) the value of the instance variable.  That 
private methods are enforced by convention rather than by the compiler 
in Smalltalk shouldn't really change anything.  If you want to provide 
yourself with accessors and you don't want anyone else to use them, put 
them in a private-something category. "someone else can change my 
variables" is not really a valid reason to avoid an otherwise-desirable 
accessor, in my opinion.  Next you could say, "I need to write all my 
code in one long method; otherwise someone could call one of the 
finer-grained private helper methods directly and get unexpected 
behaviour".  Document your interface with proper categories and then 
expect people to obey it.

If someone decides to use them anyway, screw 'em.

Note I'm not getting into the argument of whether you should or should 
not use accessors to access your own instance variables (not that I 
don't have some opinions, but I'm not getting into it :) ).

Just my 2 cents,


Juan Vuletich wrote:
> But I'm not a believer of the so called "double encapsulation". If a 
> class has an accessor methods, it allows anyone to know (and enven 
> change!) the value of the instance variable. That is against 
> encapsulation. It is the object (via its class) who defines what it 
> makes public and what it keeps private. If a subclass needs to change 
> that, it's a good time for refactoring.
> Cheers,
> Juan Vuletich

More information about the Squeak-dev mailing list