PHP
  Home arrow PHP arrow Page 2 - Using Self-Saving Objects with Command Objects in 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

Using Self-Saving Objects with Command Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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


    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
     

       

    PHP ARTICLES

    - 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
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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