Re: Attributes vs. Accessors
| From: | Philip Thompson | Date: | Mon, 25 Aug 2008 12:57:57 +0000 |
| Subject: | Re: Attributes vs. Accessors | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278657@lists.php.net to get a copy of this message | ||
On Aug 25, 2008, at 7:54 AM, Christoph Boget wrote:
1 - Attributes 1 - Accessors Do continue... Hehehe =P ~PhilipPersonally, 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, ChristophCurious. 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.