Saturday, November 26, 2011

My answer to "Which design pattern Lampcms following??"

This is my answer to a Question on Support site for LampCMS project


A complex program like this one usually implements more than one design pattern. One pattern that is well-known and is used here is Subject/Observer. Many interesting points in the program post events to event dispatcher.

Various observers are registered with the Dispatcher and listen to events and take some actions on various events. Custom modules are all observer objects and receive events and can then do stuff to the objects passed in Event, including modifying data in the object.

Other patterns I like is adapter pattern.

Also the whole program pretty much designed with MVC pattern. All web pages are actually controllers, all database related stuff is taken care by very lightweight class on top of php's Mongo classes.

There is no dedicated routing class, all requests are routed based on name of the 'a' param in URL. 'a' stand for "action''. For example a request to index.php?a=unanswered is automatically routed to 'Unanswered' class in Lampcms\Controllers\ namespace, etc.

Most classes are autoloaded based on the namespace. Base classes are always pre-loaded for extra efficiency.

The custom templating engine I wrote is very simple and fast, a template is a php class, so templates are cached by APC cache really well. There is no pre-parsing of any kind in the template, you simply pass the array of key=>value pairs to a template's parse() function and it returnes a parsed html block

There is also a REST api with read/write functions. I hope one day to start writing an Android app for this program. I know Java, I played with Android SDK before, it should be pretty easy for me to at least start an Android app. I'll make it open source also, so hopefully others will join and contribute.

No comments:

Post a Comment