Home arrow PHP arrow Expanding the Application Range of Visitor Objects in PHP 5

Expanding the Application Range of Visitor Objects in PHP 5

Has your career as PHP developer led you to learn more about the most popular design patterns? If it has, then this series may help you get a better grounding in them. Welcome to the second installment of the series “Introducing Visitor Objects in PHP 5.” Made up of three articles, this series introduces the key points of how to apply the visitor pattern in PHP, and emphasizes the practical side of the topic by walking you though copious hands-on examples.

TABLE OF CONTENTS:
  1. Expanding the Application Range of Visitor Objects in PHP 5
  2. Visiting users isn't a bad idea after all: setting up a new practical example
  3. Deriving a subclass from the User base class: creating sets of software user objects
  4. Visiting software users isn't boring at all: creating a concrete visitor class
  5. Putting the classes to work together: seeing the visitor object in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
August 09, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

If the word "visitor" doesn't ring any bells to you, let me tell you quickly what it means in the context of pattern-based programming. Essentially, a visitor object is one that's passed in straightly to another by a specific method, in order to inspect its properties and retrieve relevant information about this visited object.

Since at first glance the theory about visitors can be sometimes pretty overwhelming, in the first tutorial of the series, I introduced an easy-to-follow example, which hopefully demonstrated by a friendly approach how to create visitors with PHP 5. The example in question showed how two data handling classes could be visited by a single visitor object, in order to obtain concrete data about them, without the need to invoke specifically any of its accessing methods.

Although the example shown in the previous article may not fit all the needs of a real-world application, I think that one of the most important things here consists of understanding the primary logic behind constructing visitor objects, and then, when the pattern has been appropriately mastered, it can be used in more realistic situations.

Well, at this stage I'm assuming that creating visitor objects with PHP isn't a strange concept to you any longer, therefore I'll continue this journey by developing some additional -yet useful- examples on how to build up and implement visitors with PHP 5. The main purpose of this is simply reaffirming the concepts deployed in the first tutorial, so you can have a solid background for including your own visitor classes inside your PHP applications.

With the preliminaries out of our way, let's move on and continue learning more examples on how to use the visitor pattern in PHP. Let's go!



 
 
>>> 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: