PHP
  Home arrow PHP arrow Inheritance and Polymorphism in PHP: B...
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

Inheritance and Polymorphism in PHP: Building a Form Generator - Part III
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2005-04-19

    Table of Contents:
  • Inheritance and Polymorphism in PHP: Building a Form Generator - Part III
  • Turning back time: that old inefficient script
  • Polymorphism: the core definition
  • Implementing the Form Generator: take two
  • Listing full source code

  • 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


    Inheritance and Polymorphism in PHP: Building a Form Generator - Part III


    (Page 1 of 5 )

    In the last part of this three-part series of articles, we will find out how to improve the form generator we created in part II by learning about Polymorphism and adding it to the mix.

    Introduction

    Welcome to Part III of the series "Inheritance and Polymorphism in PHP: Building a Form Generator." I hope that you had read the previous articles, Part I and Part II, so you have a good understanding of the overall concepts explained during the development of these sections.

    If you haven't read the previous articles, let's take a quick look at what we've done for now. In order to try out some of the most powerful foundations of OOP (Object Oriented Programming), we've faced the task of applying Inheritance and Polymorphism in PHP, by taking a rather practical approach and using these pillars to create a specific project: an extensible Form Generator.

    To begin with, we defined a base class named "formObject", which is the super class from which we derived all of the necessary subclasses to generate each form element, using the power of Inheritance in PHP. Once we created the proper subclasses, all we needed to do to create our working Form Generator is instantiate some objects from the subclasses -- and that's it, we have an extensible form generator!

    Well, not so fast. If we remind ourselves of the approach taken in the previous article, we'll have to admit that using a "switch" statement to determine what type of form object we're dealing with, is extremely inefficient. Our goal is to try to fix up that method and implement a much better solution. So, what's our next route to presenting a decent approximation? The answer is Polymorphism. Sounds like another buzz word, but it's really good to learn how it can be implemented in our Web projects.

    More PHP Articles
    More By Alejandro Gervasio


       · In this final article of the series, I expose the core concepts about Polymorphism,...
       · Hi,Thanks for the article, very cool. I am new to php and trying to learn sort...
       · Thanks for the comments about the article.In fact, integrating this set of classes...
       · This is a great series of articles! Two questions though:1) Is there any way you...
       · Hello Adams,Thank you for the comments about the article. They're...
       · Here´s the full source code for each...
       · Hello Alejandro. First, thanks very much for the many interesting tutorials. A...
       · Hello,Thanks for the compliments on my PHP articles, and I really appreciate...
       · Thanks very much Alejandro. It works.Now I need to go back and compare this with...
       · I'm glad to know that all the classes I listed here were useful to get the script...
       · Hi again Alejandro.I see what my problem was. I got stuck at the step with...
       · Hello again,I'm feeling glad of knowing that the problems has been solved. Also,...
       · Dear Alejandro,Thanks for the tutorials on php to which I'm new. Having cut and...
       · Hi Vince,Thank you for the kind comments on my PHP article. Now, concerning your...
     

       

    PHP ARTICLES

    - 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
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





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