PHP
  Home arrow PHP arrow Page 2 - Expanding the Application Range of Visitor 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? 
Google.com  
PHP

Expanding the Application Range of Visitor Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2006-08-09


    Table of Contents:
  • Expanding the Application Range of Visitor Objects in PHP 5
  • Visiting users isn't a bad idea after all: setting up a new practical example
  • Deriving a subclass from the User base class: creating sets of software user objects
  • Visiting software users isn't boring at all: creating a concrete visitor class
  • Putting the classes to work together: seeing the visitor object 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


    Expanding the Application Range of Visitor Objects in PHP 5 - Visiting users isn't a bad idea after all: setting up a new practical example
    ( Page 2 of 5 )

    The visitor pattern (among others) reveals its real power when it's presented within the environment of a practical situation. Therefore I'm going to set up another example which will illustrate yet another case where this pattern can be applied.

    To begin with, I'll define a highly generic "User" class, and next create a sub class from it. This child class will expose a concrete method that will allow a visitor object to inspect and obtain all its visible properties in only one step. Sounds quite good, right? Considering this propitious scenario, take a look at the abstract class defined below, which represents the generic model of a hypothetical user:

    // define abstract class 'User'
    abstract class User{
        private $userID;
        private $firstName;
        private $lastName;
        private $postalAddress;
        private $email;
        abstract function setUserID($userID);
        abstract function setFirstName($firstName);
        abstract function setLastName($lastName);
        abstract function setPostalAddress($postalAddress);
        abstract function setEmail($email);
        abstract function getUserID();
        abstract function getFirstName();
        abstract function getLastName();
        abstract function getPostalAddress();
        abstract function getEmail();
        abstract function acceptVisitor(Visitor $visitor);
    }

    As you can appreciate, above I created a generic model of a typical user. The class also has some abstract methods, which are handy for accessing and retrieving the properties of this user, such as First Name, Last Name, Postal Address and so forth. Of course, aside from the regular accessors and modifiers, there's one method that deserves special attention. It is the "acceptVisitor()" method, which will be responsible for accepting a visitor, in order to inspect all the properties that belongs to the visited object.

    Now that I have shown you the generic structure of the "User" class, I'll derive a child class from it which implements concretely all the abstract methods declared before.

    Of course, all these tasks will be performed over the course of the next section, thus keep reading to learn how this will be achieved.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek