Home arrow PHP arrow Working with Template Classes in PHP 5

Working with Template Classes in PHP 5

A template class is a base class with some special abilities. First, it concretely implements one or more algorithms; second, it can determine which subclasses should use these algorithms. This article is the first part of a two-part series that introduces you to the basic concepts of this design pattern.

  1. Working with Template Classes in PHP 5
  2. Creating a basic implementation of the template pattern
  3. Building a simple template class
  4. Completing the model imposed by the template pattern
  5. Setting up a functional example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 18
March 19, 2007

print this article




Working with the object-oriented paradigm in PHP -- and of course, other programming languages -- implies having at least a basic understanding of its key concepts. A developer using this paradigm knows the intrinsic definition of a class, its properties and methods, and logically possesses a decent knowledge of the so-called big pillars of OOP, such as inheritance and polymorphism.

Naturally, if all of these important concepts are familiar to you, I should assume that youíve been building your own PHP classes for a while, and that very often you find yourself creating a class API that hides all the complexity required for performing a number of predefined tasks.

However, there are times when a specific object-based PHP application needs to execute extremely complex processes. In most cases, these processes are encapsulated inside one or more methods of a class (or sometimes in many of them).

While this situation happens very frequently, itís rather unusual to create classes that implement specific algorithms on top of the corresponding hierarchy. Most of the time, base classes only define the basic functionality of a group of objects, and the respective sub classes are responsible for implementing the business logic required to achieve specific tasks.

So, in which cases does the above situation occur? Well, at times itís necessary to define a base class that concretely implements one or more algorithms. Additionally, this class may need to be capable of determining which subclasses should use these algorithms. In pattern-based jargon, this class is called a ďtemplateĒ and not surprisingly, it determines the programming model imposed by the homonymous pattern.

Indeed, template classes can be very interesting within the vast area of pattern-oriented programming. Over the course of this series, Iíll demonstrate how to implement this rather unusual design pattern by accompanying the corresponding theory with copious hands-on examples.

Hopefully this experience will be instructive. Let's not waste more time in preliminaries; click on the link below to begin learning more about building template classes with PHP 5. Letís get started!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: