Reply to Re: The Singleton Pattern in PHP 5

Your name:

Reply:


Posted by Dikkie Dik on 01/14/06 13:41

> Unfortunately, this is not a good example of a singleton system.

I agree. Singletons are often used where, in procedural programming, one
would use a global variable or function. Also, the root of a library or
package can be a singleton. Examples:

$connection = Database->OpenConnection(...);

The Database class is here the root of the database package, and acts as
the root of (or the gate to) the entire database functionality. There is
no need to instantiate Database as such, because it is stateless and not
really an instance. It is more the "switchboard" that tells you where to
find the database functionality. You might even argue that a singleton
is something like a namespace.

An example of a "global variable" is, for instance, Visual Basic's Err
object, that is used for error handling. You could do that with a singleton:

ErrorLog->AddMessage(...);

The actual instance of the log object then remains "hidden" within the
ErrorLog singleton. Naturally, you could also use the namespace-like
structure:

ErrorHandling->Log()->AddMessage(...);

Where the log instance is visible, but should only be instantiated by
the ErrorHandling singleton.

Best regards

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация