Re: DB_DataObject's class generator
| From: | Alan Knowles | Date: | Sun, 12 Dec 2004 04:12:20 +0000 |
| Subject: | Re: DB_DataObject's class generator | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16184@lists.php.net to get a copy of this message | ||
I've had a few offers of patches to convert to private + setter/getters - but none have been posted yet. :)
I think the generator in cvs supports writing privates, but I havent looked at it for a little while.
There is a slight complication, as the joinAdd + links code will very likely have to be changed, as they read/write from other objects.
Regards
Alan
Markus Wolff wrote:
Torsten Roehr wrote:first of all thanks for your detailed answer! From what I've read it's perceived as good practice to *not* directly access object properties - even if this might be a bit slower. Also if your internal data structure (e.g. column/property names) change, you don't have to change all your code - just adapt the getter and everything will still work.What you describe above is indeed common practice for a lot of *other* object-oriented languages, mainly precompiled ones that aren't hit as much by the performance drawbacks. As most of the time when it comes to object-oriented approaches, it's a matter of taste. Personally, I've never needed this.With regards to PHP5 getter methods would be even more appropriate or even required for properties that are protected or private. So what about adding an option to the DO config like generateGetters which defaults to false? I can't imagine I'm the first one to propose this. What do you think - is this worth a feature request?You can of course put up a feature request for this - I'm quite interested in Alan's opinion on this topic. However, there also is the possibility of simply extending the generator class, which allows you to implement a method named derivedHookFunctions(), which must return a string that is being inserted in your DataObjects. This string can of course be a list of getter/setter methods for the DO properties. Regards, Markus