Re: Q on class failure...

From: Date: Mon, 22 Sep 2003 17:33:16 +0000
Subject: Re: Q on class failure...
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-163512@lists.php.net to get a copy of this message
On Mon, 2003-09-22 at 13:25, jsWalter wrote: > > "Raditha Dissanayake" <jabber@raditha.com> wrote in message > news:3F6E82E8.1090603@raditha.com... > > hi, > > > > It's generaly considered that constructors are supposed return an > > instance of that class. Use a factory instead if you want to return nulls; > > > A Factory? > > OK, I'll look that up, do some readng and try that route. In brief -- a factory is a function or object that returns instances of some object for which it is a factory. It is based on the analogy, for instance, whereby a car factory outputs cars. A logical example of a factory might be an object that returns user objects. The interface might be something like follows: $userFactory = &new UserFactory(); $userObj = &$userFactory->getUser( $userId ); In the above example if the user ID was not valid then $userFactory might very well return null. A special case of a factory, a singleton factory, is where the factory ALWAYS returns the same object. Such a factory might be used for a session object so that there is only ever one interface object to the session data. HTH, 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. | `------------------------------------------------------------'

« previous php.general (#163512) next »