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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 17
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT