Re: oo design question - how to avoid a factory
| From: | Andrew Nagy | Date: | Tue, 21 Dec 2004 14:48:28 +0000 |
| Subject: | Re: oo design question - how to avoid a factory | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-35196@lists.php.net to get a copy of this message | ||
Olivier Guilyardi wrote:
Andrew Nagy wrote:I guess the best way is to use the factory. AndrewJustin Patrin wrote:I think we should either switch to a factory for both PHP4 and PHP5, or not at all. For consistency. Actually, there may be a simple trick to avoid a factory : just code in a decorator method for getPaging(), that will pass the dg reference. No more $renderer =& $dg->getRenderer(). Just $dg->getPaging(), which is actually clearer. The problem with this is getPaging is specific to the html renderer. This can't go into the core dg.On Mon, 20 Dec 2004 09:59:52 -0500, Andrew Nagy <andrew.nagy@villanova.edu> wrote:Agreed, however, I would like to leave the syntax the same so that when PHP5 does become the de facto, it will make the transition very simple. If the 'new' method is used in php4, it will break silently, which I assume is bad, but since everyone seems to think it doesn't matter as long as I say how to use it in the documentation, it's not all that bad. Thoughts?Olivier Guilyardi wrote:In other words, it will silently break on PHP4 if you use the constructor? And also, you have two different syntaxes for different PHP versions. Part of the argument above is that factories aren't hard to make users use....as long as you tell them that they have to use it. I guarantee that if you allow both users *are* going to use the 'new' method much more often than they should be.Now, there may be another solution, to keep bc : In the constructor, issue a warning like "Please use the factory...", and then act as a decorator to the real datagrid. This is very possible because the Structures_DataGrid class is currently an almost empty wrapper.Here is what I would like to do. I have implemented your diff that you sent me, however instead of removing the datagrid from the constructor of the render drivers I have left that in so that PHP5 users don't have to use the factory method. How does this sound? I will check it into CVS for you to see