Re: Attributes vs. Accessors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> Curious. Which do you prefer and why?
>> For publicly-declared variables, do you access the attribute directly or
>> use an accessor?
> If it's a public member variable there is no need for plain accessor methods
> - they add no value. I feel the same about private variables with plain get
> and set accessors, there's just no point unless the accessors are doing more
> than setting and getting the internal variable.

Personally, I always use the accessor methods.

For the most part I agree with Stut -- they don't add much value.
Where it does add value, though, is in the eventuality you ever need
to change the attribute to a more restrictive visibility.  If you ever
run across this need (and I have a couple of times), the only thing
affected is the class; you don't have to worry about changing all of
your code using that class.  Conceptually, it is my preference to keep
a class as much of a black box as possible and accessor methods allow
for that.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux