Whilst working on my AOP framework for PHP, I needed a versatile iterator. Here is what I came up with:
Friday, June 13, 2008
Design Pattern in PHP: Iterator Pattern
Thursday, June 12, 2008
Javascript for PHP developers: Part I: Static Class
Here is how I would code a static class in Javascript by borrowing from my PHP experience:
Javascript | PHP |
Thursday, June 5, 2008
Design Pattern in PHP: Factory pattern
The factory pattern is most interesting when Testing and Refactoring because one can substitute a class implementation for another without changing the core code.
In the example below, I have demonstrated a versatile factory method which sports object instance creation with a variable parameter list.
- Base::factory( $className /*optional parameters*/ ) creates an object of class $className with, optionally, a list of parameters passed to the constructor
- E.g. $object = Base::factory( 'TestClass', 'param1', 'param2' );
- Base::mapClass( $sourceClassName, $targetClassName ) adds a mapping entry so that the factory builds an object instance of $targetClassName instead of $sourceClassName when asked to build for $sourceClassName
- E.g. Base::mapClass( 'TestClass', 'TestDebugClass' );
Project
The project is located at GoogleCode.
Tuesday, June 3, 2008
Design Pattern in PHP: Template Method
This next design pattern should not be mistaken with the common template conception (see Web template) more commonly found in web-technologies.
The template method pattern is designed with a base class which contains an high-level recipe and relies on sub-classes to specify the ingredients. An example would be a template for publishing a table of objects: the template method base class would implement the publishing logic whilst the sub-class would extract the relevant data pieces to expose in the table.
Project
The project is located at GoogleCode.