Re: A question of style - Properties
| From: | chuck at horde dot org | Date: | Mon, 30 Apr 2001 12:39:36 +0000 |
| Subject: | Re: A question of style - Properties | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-337@lists.php.net to get a copy of this message | ||
Quoting Mika Tuupola <tuupola@appelsiini.net>:
> Don't remember seeing any answer to this. Is there any
> opinion how should PEAR classes handle this?
>
> Personally I would prefer getProperty() and setProperty()
> methods over accessing properties directly.
It's basically an OO question. getXXX() setXXX() methods are standard practice
for public properties - in java classes, for instance. But even in java there's
nothing to prevent you from making your member variables public and accessing
them directly.
Here's a rule of thumb: if the property is something that should be exposed as
part of an object's API, then there should be get/set methods for it. That way
you can change internal data structures, variable names, add logic, etc.
without breaking your API.
-chuck