|
Posted by Richard Lynch on 01/20/05 20:47
Jason Barnett wrote:
> Think of declaration of properties and methods as a "contract". When
> something is public it is available to all of PHP. When it is private
> it is only usable by the class that you define it in. When it is
> protected it is a hybrid; it is usable to the class that defined it and
> it can be "inherited" by classes that extend that class.
>
> So, decide what level of access you really *need* for that property /
> method. If a property is only supposed to be modified by class methods
> (for example, a password string) then make it private or possibly
> protected. If everything is public access then there is temptation to
> do something like:
Back in the day, I used to code in C++
Nothing irked me more than some so-called programmer who would
over-zealously make every damned thing private.
I'd go and sub-class it, and want to make my extended class actually
USEFUL and be ham-strung by his short-sightedness.
So when you ask yourself "Self, should this be public, protected, or
private?" make sure you phrase it as:
"Can I think of ANY way in the future that some other cool programmer
would want to do fun and interesting and useful things with this?"
Let the flames begin :-)
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|