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


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