[Solar-talk] Quick thoughts on new factory() method instantiation

Travis Swicegood development at domain51.com
Mon Dec 11 14:31:13 PST 2006


Howdy all,

I imagine most have seen the new factory changes made to 
Solar::factory() where it will call a factory() method on any object it 
tries to create if that method exists.  It's a great change, especially 
with the way PHP manages memory when it comes to objects, but I'm not 
sure on the naming.  The issue is much like SPL's "Iterator" interface, 
it's generic enough that I think it might create some conflicts.  I just 
hit this myself working on some new code where factory() was a method 
name I wanted the object to implement, but I didn't want Solar calling that.

In order to avoid possible conflicts inside Solar with other objects, 
there are a few options:

1.  Create a "factory" property that if non-empty on an object would 
specify the name of the "factory" method to call

2. Use solar_factory() as the factory method that Solar::factory() calls

3. Use __factory() a teh factory method that Solar::factory() calls


I like the looks of option three the best, but I'm not crazy about the 
possible confusion with the PHP level magic methods which have scoped 
out the double underscore as their namespace.  Option one gives everyone 
the most flexibility, while option two seems to be the one that would 
allow the most standardization.

Any thoughts?
-Travis


More information about the solar-talk mailing list