Home arrow PHP arrow Introducing the Facade Pattern in PHP 5

Introducing the Facade Pattern in PHP 5

The facade pattern may be one of the less well known patterns in PHP, but it definitely has its uses. In this first article of a two-part series, you'll learn the basics of how the facade pattern works, illustrated with numerous examples.

TABLE OF CONTENTS:
  1. Introducing the Facade Pattern in PHP 5
  2. A basic implementation of the facade pattern
  3. Using HTTP compression with PHP 5
  4. Completing the facade schema
  5. Seeing the facade pattern in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
January 16, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As youíll certainly agree, pattern-based PHP programming is sometimes a hard-to-master topic. It logically has to be addressed with a considerable level of knowledge (and experience, to be frank), more specifically in those cases where the design pattern to be implemented presents a high grade of abstraction.

Of course, this doesnít mean that all of the PHP applications that youíre going to develop from this point onward must solve programming-related problems by utilizing a particular pattern. However, learning how to apply different design patterns to tackle common and well-known issues may help to expand your existing background as PHP developer, in addition to improving your overall experience.

Assuming that the previous paragraphs already convinced you that learning pattern-based programming with PHP might be an instructive and educational experience, in this series, which is comprised of two comprehensive articles, Iím going to introduce the foundations of an interesting structural pattern. Iím talking specifically of the facade pattern.

Since I have to admit that this one isnít very commonly used amid the huge terrain of PHP-based web development, let me first walk you through a brief introduction about what it does. In this way you can anticipate what youíll learn in the course of these two articles.

To put it simply, the facade pattern can be applied in those situations where you need to create a PHP class which requires the implementation of a complex system as part of one of its methods. At first glance, the previous definition sounds like something applicable in many cases, but the advantage of using a facade schema relies on the point that the class can hide all the logic of the mentioned mechanism, while the mechanism in question knows nothing about the calling class. That sounds pretty good, right?

To clarify the above concepts a bit more, allow me to cite an illustrative example: suppose you have a class which uses a complex set of additional classes to serialize/unserialize different objects before saving them to a database table. In this case, you have a class that hides all the complexity required for serializing the mentioned objects, but thereís also a group of classes that know nothing about the class that called them. As you can see, these classes are only responsible for performing the serialization/unserialization sequence on several objects and nothing else. Period.

Now, are youíre starting to grasp the logic behind the facade pattern? Of course you are!

At this moment , and after explaining a few basic points on how to use the facade pattern with PHP, letís move forward and learn how all these theoretical concepts can be translated into some functional hands-on examples. Are you ready? Good, letís get started!



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