PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP-Tip-a-Day: PHP Tutorial: The Legend of the Singleton

Note: This article was originally published at PHPDeveloper on 18 April 6156.
PHPDeveloper

Following his recent allegory about the Factory pattern (as described in story form) Greg Bulmash has posted the Legend of the Singleton to help with your understanding this pattern.

The Singleton pattern provides an interface to let your application always pull out the same object (or make a new one if it needs to).

His legend talks about kings, mythological data sources and the overloading of multiple "hoses" (connections) to it. Also included is a code example showing a simple database class that includes a "getInstance" method acting as the Singleton to return either a new or the (same) current instance.