PHP
  Home arrow PHP arrow The Basics of Using the Prototype Pattern with 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

The Basics of Using the Prototype Pattern with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2007-05-15


    Table of Contents:
  • The Basics of Using the Prototype Pattern with PHP 5
  • Implementing the prototype pattern
  • Creating an additional prototype class
  • Testing the prototype pattern

  • 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


    The Basics of Using the Prototype Pattern with PHP 5
    ( Page 1 of 4 )

    The prototype class lets you use many instances of a specific class, without copying objects to different variables. This article, the first of a two-part series, demonstrates the basic functionality provided by this pattern.

    Introduction

    If you're a PHP developer who has been building web applications with the object-oriented paradigm for a while, then you'll have a solid background in how to create classes and define their properties and methods, in addition to handling their instantiation in accordance with the business logic implemented by your PHP scripts.

    Now that I mentioned the term "class," surely it'll be familiar to you that this programming structure is in fact a blueprint. This blueprint is used for all the eventual objects created from it, which logically will expose a behavior consistent with the methods defined by the class in question.

    Expressed in simple terms, when you define a class in the context of a given PHP application, what you're actually doing is creating a prototype model that will be implemented by one or more instances of the originating class. Naturally there will be some variations, particularly if you're working with subclasses that override and overload methods defined by the respective parent.

    However, there's one thing in particular that I'd like to analyze in detail concerning the definition expressed in the previous sentences. As you may have noticed, I said that it was possible to work with more than one instance of a class, even though this circumstance may happen rather infrequently.

    Logically, if this condition ever occurs, it'll be necessary to build a mechanism that allows one to easily deal with multiple instances of one class, without having to complicate the source code of a certain application with complex, and sometimes inefficient, programming methodologies.

    The situation described above is the perfect scenario for implementing the prototype pattern, since it will let you use many instances of a specific class, without copying objects to different variables. At this time you may be wondering how this can be achieved. Well, in plain terms when the prototype pattern is applied, the first instance of a class is used as a prototype model, and all the other instances of the class in question are created by cloning the mentioned prototype object.

    Although at first glance the definition of the prototype pattern seems a bit complicated, the truth is that it can be implemented by a few functional PHP code samples very easily. That will be the main goal of this two-part series. More concretely speaking, in this first tutorial of the series I'm going to demonstrate only the basic functionality provided by this pattern, while in the second article I'm going to use the pattern in a more useful situation, that is building an extensible data validation system.

    Now that you know the wealth of interesting topics that will be covered in this series, let's start learning the key concepts of the prototype pattern. Let's begin this educational journey now!



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





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