News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPBuilder.com:
Implementing the Singleton Pattern in PHP 5
November 24, 2010 @ 13:44:13

If you haven't taken much of a look at design patterns and how they can help your development life, the Singleton pattern is a good place to start. On PHPBuilder.com there's a new tutorial introducing this handy pattern and how it might fit your needs.

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). [...] 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 [...] because your application should have only a single instance in order to avoid conflicting requests for the same resource and to minimize performance issues.

He shows an example of how to implement it, first as a class template and then in actual use (complete with code ready to copy and paste). He also shows how you can use the singleton pattern to act as a frontend to other classes, making a sort of polymorphism simple. Thankfully, he also explains some of the risks in using this design pattern and that "less is more".

1 comment voice your opinion now!
singleton designpattern tutorial polymorphism


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Back to Basics: Managing PHP Configuration php.ini Directives

MaltBlue.com: Zend Form Mastery with Zend_Config - Part 2, Core Form Configuration

Tony Bibbs' Blog: HOWTO: Deploy Your Application Using PEAR

Zend Developer Zone: Profiling PHP Applications With xdebug

IBM developerWorks: Implement access control with Agavi


Community Events





Don't see your event here?
Let us know!


opinion series laravel language install framework interview security introduction podcast version package application voicesoftheelephpant composer library community tool release symfony

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework