The Template Pattern in PHP 5

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ltruett@fluffycat.com

    #1

    The Template Pattern in PHP 5

    ....and I've finally completed my series of GOF design patterns using
    PHP 5 with the Template Pattern.



    This is a pretty useful pattern, and one that you could easily use
    without even realizing it is a pattern.

    Essentially you have an abstract template class that defines a
    non-abstract method with an algorithm. Also in the abstract template
    class are more methods which said algorithm will use. Some of these
    methods are be abstract and must be defined by any concrete extending
    classes, while others are not abstract and may be defined by any
    concrete extending classes. In the Template pattern, the non abstract
    methods should do nothing if not extended.

    Pretty simple, basic abstract class stuff. One interesting point here
    is that the algorithm in the abstract class controls the main flow of
    things, where as ordinarily a method in the extending classes would do
    this.

Working...