Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Contribute
Contribute
Link to Us
Linux Jobs


Top White Papers

More on LinuxToday


Implementing the Singleton Pattern in PHP 5

Nov 25, 2010, 19:03 (5 Talkback[s])
(Other stories by Octavia Andreea Anghel)

"As you probably know, in software engineering there is a set of design patterns that are universally tested, approved and accepted as advanced recipes for programming. One of these patterns is the Singleton design pattern, which is based on the mathematical concept of a singleton (a set with a single element). Part of the well-known Gang of Four (GoF) design patterns, it calls for restricting the instantiation of a class to one object. (Those who are familiar with design patterns may be interested to know that the Singleton pattern in itself is an implementation of the Responsibility pattern.)

"Sometimes the Singleton pattern can help complete important programming tasks, but only you can decide where and when it fits your needs. As a pointer, the Singleton pattern fits well when you manage a shared resource -- a printer, a file manager, a database connection, loggers, and so on -- because your application should have only a single instance in order to avoid conflicting requests for the same resource and to minimize performance issues.

"Before deciding to use the Singleton pattern, you should first answer "yes" to three main questions:"

Complete Story

Related Stories: