Home arrow PHP arrow Introducing Visitor Objects in PHP 5

Introducing Visitor Objects in PHP 5

Although the article’s title may seem a bit intimidating, the truth is that things are much simpler than you think. Like many other programming languages, PHP also allows you to construct and use visitor objects with minor hassles. But, before I go deeper into the subject, first let’s ask ourselves the following question: what are visitor objects, after all?

TABLE OF CONTENTS:
  1. Introducing Visitor Objects in PHP 5
  2. An introductory example
  3. Defining another sample class
  4. Defining the structure of a visitor
  5. A visitor object in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 11
August 02, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

Well, if you've been using design patterns for a while in your PHP applications, then you've probably heard about the Visitor pattern. If you haven't yet, let me give you a short description of what this pattern does. In simple terms, when it's applied appropriately, the pattern allows you to build up objects that literally visit other objects to obtain information about the target objects. This process is usually done by inputting the visitors into the visited objects via a concrete method. 

To put it simply way, suppose that you have a bunch of objects that represent, in the software universe, the profiles of several users. This example looks pretty familiar, doesn't it? Well, it's possible to create a set of objects that "visit" these users and obtain certain information related to them, such as First and Last Name, user IDs, email addresses, and so forth. The exciting aspect of this situation is that this entire process can be performed programmatically, by using some simple classes, and as you know, PHP makes working with objects a no-brainer task.

So that's a small portion of theory of building visitor objects. Nevertheless, you'll agree with me that one of the most interesting aspects of design patterns is precisely their practical side. Therefore, considering this undeniable fact, in conjunction with your permanent wish for extending your background in object-oriented programming with PHP, over the course of this series I'll be showing you some useful examples of how to build visitor objects, and more specifically how to include them in real-world applications.

Assuming that creating visitor objects with PHP has already caught your attention, let's introduce ourselves to the subject and start learning more about it.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: