Jari Williamsson
2/13/2008 7:21:00 AM
Philipp Hofmann wrote:
> On Mon, Feb 04, 2008 at 06:57:21PM +0900, Ryan Davis wrote:
>> On Feb 3, 2008, at 18:18 , Philipp Hofmann wrote:
>>
>>> basicly it's a 2nd encapsulation of an attribute within an object that
>>> undermines the encapsulation that comes with oo design.
>> How exactly does making/using an accessor method "undermine the
>> encapsulation"?
>
> what i meant is:
>
> accessors are meant to make the instance variables of an object to be
> accessible from outside. creating accessors for every variable used in
> an object (in order to get rid of @s) makes every variable accessible
> from outside the object. therefore the data is not encapsulated any
> more.
The data is still encapsulated, although the standard attr_accessor and
attr_writer lets everything just pass through. But writing an accessor
that for example prevents data to be set to certain values isn't exactly
a hard task.
But since Ruby has a method to access the instance variables directly
anyway, the encapsulation is "undermined" even without accessors.
Best regards,
Jari Williamsson