PHP
  Home arrow PHP arrow Page 2 - Using Self-Saving Objects with Command...
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Using Self-Saving Objects with Command Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 7
    2006-12-26

    Table of Contents:
  • Using Self-Saving Objects with Command Objects in PHP 5
  • Defining a core module of the command pattern
  • Storing and loading self-saving objects
  • Completing the command pattern
  • Seeing the command pattern in action

  • 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


    Using Self-Saving Objects with Command Objects in PHP 5 - Defining a core module of the command pattern


    (Page 2 of 5 )

    In order to start developing the final example included in this series, I’ll define an object command class. As you may guess, this class will be tasked with sending two specific orders to the commanded object, implemented via a couple of straightforward methods. The first method will instruct the commanded to save itself to a text file, while the second method will indicate that the object in question must be loaded from that file.

    Having explained the functionality that I plan to give to commander and commanded objects respectively, I’ll begin listing the generic definition for this object command class. Its signature is the following:

    // define abstract 'ObjectCommand' class (the commander)
    abstract class ObjectCommand{
    protected $objectCommanded;
    public function __construct($objectCommanded){
    $this->objectCommanded=$objectCommanded;
    }
    abstract public function executeCommand();
    }
    

    As you can see, the object command class listed above accepts an instance of the respective commanded, which is directly assigned as a new data member. In addition, you can appreciate that there’s an abstract method which is called “executeCommand().”

    Logically, after giving a concrete implementation for the previous method, the command class will be capable of instructing the commanded object to save itself to a given text file, or perform an auto-loading process from the mentioned file.

    Now, having defined the general structure for the corresponding command class, come with me and visit the following section. You’ll learn how to derive two concrete classes from the respective parent to implement the pertinent “save()” and “load()” instructions on a commanded object via the previously created “executeCommand()” method.

    To see how these brand new command classes will be properly defined, please read the following section.

    More PHP Articles
    More By Alejandro Gervasio


       · Over the course of this article of the series, some command classes are utilized for...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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