PHP
  Home arrow PHP arrow Working with Template Classes in PHP 5
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Working with Template Classes in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2007-03-19

    Table of Contents:
  • Working with Template Classes in PHP 5
  • Creating a basic implementation of the template pattern
  • Building a simple template class
  • Completing the model imposed by the template pattern
  • Setting up a functional example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with Template Classes in PHP 5


    (Page 1 of 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.

    Introduction

    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


       · Over the course of this article (the first part of a two-part series), you'll learn...
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway