News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Devshed:
The Basics of Using the Prototype Pattern with PHP 5
May 16, 2007 @ 07:53:00

DevShed gets back to its series looking at design patterns with this new tutorial covering the Prototype pattern. This pattern is commonly used when its too "expensive" to create an object in the usual way in an application.

The prototype class lets you use many instances of a specific class, without copying objects to different variables. [...] 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.

In this first part of the series, they start by creating a class - DataPrototype - to act as a foundation for the rest of the tutorial. On top of the DataPrototype, they build two new classes:

  • an ArrayPrototype class that as methods for getting the size and data in an array as well as setting its contents
  • a FilePrototype that has methods for reading file information and saving new data out

Finally, they show it in action, first the ArrayPrototype, then the FilePrototype both setting the data of their respective storage method then getting its size.

0 comments voice your opinion now!
tutorial php5 designpattern prototype basic tutorial php5 designpattern prototype basic


blog comments powered by Disqus

Similar Posts

Pádraic Brady's Blog: XSS in PHP (Part 1): How Not to Use Htmlspecialchars

PHPMaster.com: Error Logging with MongoDB and Analog

Tim Koschuetzki's Blog: How To Transform HTML To Textile Markup - The CakePHP TextileHelper Revisite

DevShed: Defining a Custom Function for File Uploaders with PHP 5

DevShed: Using Static Methods to Build Loader Apps in PHP


Community Events

Don't see your event here?
Let us know!


series library application api opinion example interview conference voicesoftheelephpant podcast release introduction laravel version symfony2 performance php7 community extension framework

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework