PHP
  Home arrow PHP arrow Introducing the Flyweight 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? 
Google.com  
PHP

Introducing the Flyweight Pattern with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 17
    2007-02-26


    Table of Contents:
  • Introducing the Flyweight Pattern with PHP 5
  • Defining a target class
  • Defining a flyweight factory class
  • Seeing the flyweight pattern in action

  • 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


    Introducing the Flyweight Pattern with PHP 5
    ( Page 1 of 4 )

    Among the considerable variety of structural design patterns that can be implemented with PHP 4 (and PHP 5, by the way), there’s one in particular that deserves special attention. It's easy to apply in the context of a given web application, and it offers remarkable functionality when it comes to preventing the unnecessary instantiation of different classes. This two-part series covers that pattern.

    Naturally, if you already read the title of this series, then you’ll know that I’m speaking specifically of the flyweight pattern. But before I go into further explanations, let me tell you briefly how this pattern works. This will give you a better idea of how and when it can be used.

    In simple terms, when the flyweight pattern is applied, it’s possible to specify programmatically that a particular class is going to have only a predefined number of instances, which are shared within the same implementation. This simple concept itself introduces an immediate benefit: it prevents unnecessary instantiations of the class in question across the same application, which results in a noticeable improvement in the performance of certain systems that must work with heavy loads.

    Certainly, if you reread the above definition, it’s clear to see that a flyweight class can be considered a straightforward approach to keep the creation of objects carefully balanced. This can improve the web server’s overall performance, as I mentioned a few lines above.

    Nonetheless, this series isn’t limited to introducing boring theory on how the flyweight pattern works. You'll have the chance to learn and test many practical examples related to the referenced pattern, so you can quickly start applying it in your own PHP applications.

    A final note before I proceed further: all the examples that you’ll see here will be developed with PHP 5, but they can be easily modified to work with PHP4 as well.

    Having clarified that point, let’s find out together how to implement flyweight classes with PHP. It’s going to be instructive and fun!



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

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek