PHP
  Home arrow PHP arrow Page 4 - Expanding the Application Range of Vis...
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

Expanding the Application Range of Visitor Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      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


    Expanding the Application Range of Visitor Objects in PHP 5 - Visiting software users isn't boring at all: creating a concrete visitor class


    (Page 4 of 5 )

    It's quite possible that you're wondering how a visitor class can be coded to allow all its properties to be retrieved without having to use its accessing methods. Well, fortunately your question can be answered in two easy steps: first, I'll define the generic structure of a visitor class, and then I'll create a subclass from it.

    Indeed, this sounds logical, thus in accordance with this approach, below I listed the signature of the abstract "Visitor" class:

    // define abstract 'Visitor' class
    abstract class Visitor{
        abstract function visitSoftwareUser(SoftwareUser $softwareUser);
    } 

    That's all I need to define the generic model of a visitor. Notice the declaration of the abstract "visitSoftwareUser()" method, which will accept as input argument the visited object, in this case represented by an instance of the "SoftwareUser" class.

    Now that you know how the prior abstract class looks, it's time to implement its visiting method. That said, here is the corresponding definition of the entirely new "SoftwareUserVisitor" subclass:

    // define concrete 'SoftwareUserVisitor' class
    class SoftwareUserVisitor extends Visitor{
        private $softwareUserInfo=array();
        // obtain user information as array
        public function visitSoftwareUser(SoftwareUser $softwareUser){
            $this->softwareUserInfo['userid']=$softwareUser-
    >getUserID();
            $this->softwareUserInfo['firstname']=$softwareUser-
    >getFirstName();
            $this->softwareUserInfo['lastname']=$softwareUser-
    >getLastName();
            $this->softwareUserInfo['postaladdress']=$softwareUser-
    >getPostalAddress();
            //$this->softwareUserInfo['email']=$softwareUser-
    >getEmail();
            $this->softwareUserInfo['software']=$softwareUser-
    >getPreferredSoftware();
        }
        public function getSoftwareUserInfo(){
            return $this->softwareUserInfo;
        }
    } 

    As you can see, now this brand new class offers a concrete implementation for its "visitSoftwareUser()" method. It's clear to see here how all the properties of an object of type "SoftwareUser" are retrieved by the visitor in question, and additionally, to make things even easier, they're stored in an array. Short and understandable!

    At this level, after defining the two classes that allow the implementation of the visitor pattern, that is, the visited and visitor classes respectively, it's a good time to watch them together in action.

    Not surprisingly, that's exactly the subject that I'll cover in the next few lines. Keep reading; I'll be waiting for you in the following section.

    More PHP Articles
    More By Alejandro Gervasio


       · Over the course of this second installment, I'll go deeper into the implementation...
       · I'm looking forward to this practical example.
       · Hello,The example has been included into the tutorial.Thank you.
       · In the last example, the lines: // visit 'SoftwareUser' object ...
       · Thank you for introducing your feedback regarding this article. Concerning your...
       · The comments by Anonymous Loozah at: 08-11-06 @ 5:03 am EST seem a bit harsh. ...
       · Hi Larry,First off, thank you for the compliments on this PHP article; I see you...
       · I agree with Larry, so want to thank Alejandro for writing these articles. It's very...
       · Hello Matthijs,Thank you for introducing your comments on my PHP article. In...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - 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
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





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