[squeak-dev] Instance variable access in superclasses.

Ramon Leon ramon.leon at allresnet.com
Tue Nov 25 23:49:02 UTC 2008


> 
> Hi all.
> 
> What would people's reaction be if a class was prevented from 
> being able to directly access its superclass's instance 
> variables? 

I would object.

> A subclass should use accessor methods to access a 
> superclass's instance variables.

Says who?

> Is there any particular reason subclasses get access to 
> superclass instance variables? I think it breaks encapsulation.

Then we have different definitions of encapsulation.  To me encapsulation
means one object can not directly access the state of another object but
must use messages for communication.  

If class #B inherits from class #A an instance of class #B is only *one
object*; i.e. super is not another object but the same object as self and
thus the object should have direct access to *all* of its own instance
variables regardless of where they lie in the inheritance tree.  I don't
think encapsulation was intended to protect an object from itself.  That's
my 2 cents!

Ramon Leon
http://onsmalltalk.com




More information about the Squeak-dev mailing list