PHP
  Home arrow PHP arrow Page 3 - 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 - Storing and loading self-saving objects
    ( Page 3 of 5 )

    As I stated in the previous section, the next step that I’m going to take to apply the command pattern will involve deriving two child classes from the parent “ObjectComand.” In simple words, the tasks performed by these two classes will consist of instructing the commanded object about saving and loading itself from a given text file.

    That being said, here are the signatures for these child command classes. Take a look at them, please:

    // define concrete 'SaveObjectCommand' class (implements concretely the 
    'executeCommand()' method class SaveObjectCommand extends ObjectCommand{ public function executeCommand(){ $this->objectCommanded->save();         } } // define concrete 'LoadObjectCommand'class (implements concretely the
    'executeCommand()' method class LoadObjectCommand extends ObjectCommand{ public function executeCommand(){ return $this->objectCommanded->load(); } }

    Definitely, after seeing the source code that corresponds to the pair of command classes listed above, you’ll have to agree with me that they’re actually very simple, but at the same time quite powerful.

    Please notice how each one of their “executeCommand()” methods uses an instance of the commanded object to call “save()” and “load()” respectively. From examining only these two methods, it’s clear to see how a commanded object is capable of housing all the programming logic required for execution in the pertinent commanders. Undoubtedly, this kind of relationship between classes shows in  a nutshell how the commander pattern can be easily implemented with self-saving objects. Pretty good, right?

    So far, so good. At this point, you learned the corresponding definitions for the two object command classes that were shown before. However, there’s still a missing piece concerning this schema, since the respective commanded object hasn’t been defined yet.

    Therefore, in the next few lines I’m going to show how to create a self-saving commanded object which will complete the implementation for the already popular command pattern.

    As usual, if you want to learn how this commanded class will be created, 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 5 Hosted by Hostway
    Stay green...Green IT