class FOO { function Fred() { echo "Fred in FOO"; } } class BAR { function Fred() { echo "Fred in BAR"; } } class BAZFactory { function BAZFactory() { } function getInstance( $type ) { if( $type == 1 ) { return new FOO(); } else if( $type == 2 ) { return new BAR(); } else { return null; } } }
// Factory load cost. $factory = new BAZFactory(); $obj = $factory->getInstance( 1 ); // 1 level of indirection, if used often it more than pays // for the factory load cost. $obj->Fred(); Cheers, Rob. On Thu, 2003-09-25 at 04:25, jsWalter wrote: > > "Martin Towell" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > What about something like this? > > <snip> > > I've been playing with that same approach this evening. > > But I guess I was hoping for a more direct, 1 level of inderection instead > of 2. > > But, by making a "base" method in the main class, and it knowing about the > second level of indirection, that sort-of solves the issue. > > Thanks for your time and thoughts. > > It help clarify my thinking and approach, and just showed me that I wasn't > to far off the path, as it were. > > Walter > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php