Home arrow PHP arrow Introducing Bridge Classes with PHP 5

Introducing Bridge Classes with PHP 5

The bridge class, or what's commonly known as the bridge pattern, lets you create a class with its abstract functionality and implementation residing on different class hierarchies. This lets you decouple the class from its concrete application. This article, the first of three parts, introduces you to the bridge pattern and its uses.

TABLE OF CONTENTS:
  1. Introducing Bridge Classes with PHP 5
  2. Introducing the basics of the bridge pattern
  3. Implementing the bridge pattern’s core logic
  4. Implementing the logic of a bridge class in a different hierarchy level
  5. Seeing the bridge pattern in action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 7
January 03, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

If you’re a PHP developer who has a significant background in developing object-based applications, then possibly you’ll agree with me that when it comes to implementing an approach for decoupling the logic of a given class from its concrete implementation, there are some trusted techniques that can be applied successfully.

Among others, the factory pattern is one of the cases that best applies the concept that I described above. When this pattern is used, it’s possible to create a class that simply “returns” objects to calling code, without having to worry about how these objects behave inside the context of a given application or even how long they persist during the request of multiple PHP files.

However, and now speaking more specifically, using a factory class inside an application implies that you can decouple the logic that stands behind all the created objects from the corresponding creator. At the same time, this means that multiple objects (at least two) are involved in the creation process. Without a doubt, the situation that I illustrated a few lines ago should bring up the following question: is it feasible to work with only one class (not many classes) that can be decoupled from its concrete implementation?

Fortunately, the answer to the above inquiry is a loud "Yes!" To give you an example covering the topic in question, think about an abstract class, where its implementation is most of the time separated from its declaration. That sounds really good, and indeed the application of abstract classes is an important link in the chain of object-oriented programming, but definitely it’s not the only approach used for separating a class from its implementation.

Assuming that you’re interested in learning an alternative approach for achieving the mentioned decoupling process, let me now introduce the concept of “bridge” classes, or what’s more generally known as the bridge pattern. In this specific case, it’s possible to create a class where its respective abstract functionality and implementation reside on different class hierarchies, in this way allowing you to decouple the class in question from its concrete application. And best of all, the referenced procedure can be performed without using abstract classes at all.

Of course, I’m pretty certain that all this theory on applying the bridge pattern seems to be a hard thing to grasp, but in fact it’s much simpler than you think. Thus, in this series, which is comprised of three tutorials, I’m going to teach you how to create and use bridge classes with PHP 5, by showing you numerous hands-on examples that can be easily included in your own PHP applications with minor modifications.

Ready to learn more on how to apply the bridge design pattern with PHP? All right, let’s no waste more time in preliminaries and begin now!



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

blog comments powered by Disqus
   

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

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: