PHP
  Home arrow PHP arrow The Basics of Using the Prototype Patt...
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 
Actuate Whitepapers 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · This first tutorial of the series shows how to implement the prototype design...
       · What is the difference between cloning a class/object and creating new instances of...
       · Thank you for posting your comments on my PHP article. Concerning your question, the...
       · Sorry the question was not the difference between copying and cloning, but rather...
       · When you create an instance of a class in PHP 5, by default this instance is a...
     

       

    PHP ARTICLES

    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...




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