So I attended the Atlanta PHP meeting last week and it was fun just like the previous time. I find this particular group fun and knowledgeable making me look forward to the next meeting. The topics covered this time were the singleton design pattern and the Moodle course management system. It seems like we are going to start covering a design pattern plus another topic during each future meeting which I think is a great idea. You can never know enough about design patterns.

Singleton Pattern

So there wasn’t much said that was new to me about the singleton pattern. It’s pretty standard, the objective of this pattern is to prevent creating multiple instances of a class. The code example was something like this:

class Singleton
private static $instance;

protected function __construct(){}

public static function getInstance()
if(!self::$instance instanceof self)
self::$instance = new self;
return self::$instance;

You declare a static var to track the instance of the class. Then you make a protected (or private depending on your needs) constructor so it can’t be called outside the class. Finally, anywhere you need to call this class, you call it’s static method getInstance() to either instantiate the class the first time or return the instance any other time. The example used in the meeting for using the singleton pattern was a messaging service. You want to create one instance of the messaging class to track incoming and outgoing messages. Accidently creating two instances or more would create confusion and/or messages not handled correctly.

The last comments on this pattern were making sure not to overuse it. Some developers out there see the singleton pattern as the anti- pattern. They say using singletons is the same as creating globals which they frown upon. I personally like using it but I do agree it should be used where needed not used because it’s there.


From the Moodle web site: Moodle is a course management system (CMS)—a free, Open Source software package designed using sound pedagogical principles, to help educators create effective online learning communities. You can download and use it on any computer you have handy (including webhosts), yet it can scale from a single-teacher site to a University with 200,000 students.

Moodle seems very neat and extremely robust. It took only a couple minutes to setup from scratch. The UI is ok, could use some updating. Because there are so many options, I had a hard time setting up a course until I read the documentation but now I have a better idea of how it works and I can create a course with content and quizes fairly quickly. There are tons of modules for Moodle to give it more functionality. Overall seems like a good product. If in the future I need a CMS I’ll seriouly consider using Moodle.