PHP
  Home arrow PHP arrow Page 3 - 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 - 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


       · 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 5 hosted by Hostway
    Stay green...Green IT