Re: how to mark protected properties?
| From: | Alan Knowles | Date: | Tue, 08 Jun 2004 00:41:42 +0000 |
| Subject: | Re: how to mark protected properties? | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-30116@lists.php.net to get a copy of this message | ||
Sounds like someone paid too much attention in the java lessons.. - perhaps certain components of a banking applications where encapsulation is essential this theory holds true, but for a highly re-usable, easy to understand lightweight libraries, encapsulation has to be treated with a high degree of restraint.
A number of my classes attempted to ecapsulate data early on, and over time people have requested access to those variables, most of the time it was not critical to have them private in anyway.. - so they just became public. This has happened in a number of other PEAR classes I've used. - the author made something private, that didnt need to be, and occasionally, it ended up more efficient to either extend/ignore the private or just fork the code.
I have a suspician this situation is going to get far worse with PHP5, if library authors are going to insist on using private and protected keywords alot, then when it comes to reuse the code, and it doesnt quite fit the requirements, rather than a workaround of extend / access privates, a full copy paste replacement is going to become more common. (hence making these kludges even worse to maintain than before..)
Personally I think we should ban Protected :) - as it enforces the extension pattern over a (whatever that other one is) pattern. on the end user..
Regards
Alan
Hans Lellelid wrote:
Lukas Smith wrote:Bertrand Mansion wrote:Perhaps not, but accessing properties directly removes a huge amount of flexibility from application design -- by making requirements not only on the API of classes (for BC) but also the inner-workings of a class. I would say encapsulation is at least half the point of using OO in the first place, so I'd heartily agree with Bertrand. Everything should be private/protected and hence prefixing every var with '_' seems to make little sense. .02/Hans-1 Everything should be protected by default in OO code. PHP makes everything public by default, that's just a design error and defeats the whole point of data encapsulation, probably due to BC. I won't prefix all my instance vars with _. Users are free to refer to the API documentation.100% pure encapsulation is not efficient