From: Gavin Sinclair Date: 2002-11-08T08:30:23+09:00 Subject: Re: Making Instace Variables Private/Local From: "William Djaja Tjokroaminata" [snipped] > (In > other words, whether you decide that it is perfectly fine that a child > class accesses its parent class data directly in terms of '@var' and not > 'self.var'.) > > > Bill The only other OO (rather, OI - Object Influenced) languages I know are C++ and Java. In both of these, derived classes have access to parent classes' public (obviously) and protected instance variables. It seems that the Ruby model is that all instance variables are a mix: - protected, because children can access them; and - private, because other objects of the same class *can't* access them If C++ and Java allow derived classes to access parent's instance variables, then why not Ruby? Granted, at least in these languages, instance variables can be made genuinely private, but I don't think it would make sense for Ruby to make *all* instance variables private. In my (limited) experience, there is less need for inheritance in Ruby than in C++/Java, because dynamic binding takes place all the time, and because classes can be modified. This is great, because in Ruby you only inherit when it genuinely makes sense, rather than as a convenience for modifying behaviour. A corollary of this is that you should be able to manage your inheritence trees sufficiently to avoid trampling on parent's data. Just my 2c. Gavin