On Sun, 2003-09-21 at 14:10, Gerard Samuel wrote: > Robert Cummings wrote: > > >Are you looking to create a single point of access to any libraries your > >application may wish to use > > > Yes. Instead of juggling 5-6 objects, just move around one object. > > > and to subsequently base this on a singleton > >pattern (only one instance of the object may exist?)? > > > Yes. Currently in my code, there is the ADODB object, which is used as > normal. > I pass this object by reference to Smarty so its plugins can access the > DB if neccessary, > and two other classes that need DB access. Im going on the assumption, > that > if one doesn't have to pass by reference, then dont do it, especially > large objects, > and having multiple copies of them. > > All of this is just a thought. Whether its feasable, is another story > for my app....
This may be seem like a shameless plug but I think it's relevant. In the InterJinn framework i created I had a similar issue. PHP has the horrible issue that when passing objects around it copies them (this is fixed in PHP5 from what I hear). This causes extra processing to copy large objects which have big data sets, and makes it extremely difficult to properly implement a singleton pattern. In the InterJinn framework what I did was create a wrapper class, but rather than having other classes extend it, I have a core loader service which takes a string name as a parameter and returns the associated object (database, session, cache, etc.). The returned object however is not the actual object, but rather an instance of the wrapper class with a single instance variable called do, the do variable is a reference to the real object. Thus if someone copies the returned object they only copy the wrapper, and the internal reference is maintained. It makes for slightly odd syntax: $dbManager->do->getConnection( 'default' ); but the cost of the intermediate lookup is extremely small and it prevents issues where copies of an expected singleton are made. In cases where a user wants to optimize and actually work with the references, they can always do: $dbManager = &$this->getServiceRef( 'databaseManager' ) $db = $dbManager->getConnection( 'default' ); instead of the nanoscopically slower: $dbmanager = $this->getService( 'databaseManager' ); $db = $dbManager->do->getConnection( 'default' ); Anyways maybe that will help you with your own problem. Cheers, Rob. -- .------------------------------------------------------------. | 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