Home arrow PHP arrow Abstracting Database Access Using Polymorphism with Objects in PHP 5

Abstracting Database Access Using Polymorphism with Objects in PHP 5

Polymorphism is an object-oriented programming concept that can be difficult to understand. This article, the first of a three-part series, walks you through the basics of Polymorphism so that you can make use of it in your own applications. The specific example in this article will show you how to use it with different database systems.

TABLE OF CONTENTS:
  1. Abstracting Database Access Using Polymorphism with Objects in PHP 5
  2. What shouldn't be done when accessing distinct database systems
  3. Using Polymorphism to create a database abstraction layer
  4. Demonstrating the functionality of Polymorphism
By: Alejandro Gervasio
Rating: starstarstarstarstar / 16
March 21, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

Since the introduction of a highly improved object model in PHP 5, developing object-based applications with the latest version of this neat scripting language has been a greatly simplified process. This is naturally due to the implementation of diverse and powerful object-oriented features, such as visibility of class members, type hinting and exceptions, to name a few.

However, while it should be admitted that the aforementioned improvements indeed facilitate working with classes and objects in a straightforward way, it's also true that building object-oriented applications can be a hard-to-master process. Most of the time this is because of inadequate knowledge of the main pillars of the object-oriented paradigm.

In this case, you'll possibly know that I'm talking about Inheritance and Polymorphism. But what can be wrong with putting these theoretical concepts into practice, after all? Well, if you've been developing object-based programs for a while, then you've probably been consciously defining parent classes here and there. Logically you've also created numerous subclasses to perform concrete tasks.

I have to admit that Inheritance is rather easy to grasp. It can be applied successfully with only a decent background in object-oriented programming. Nonetheless, there's a part of this schema that very often is completely omitted, or misused, in the best case. As you may have guessed, I'm speaking of Polymorphism, certainly a concept that presents some abstract aspects. Consequently, it's much harder to apply than Inheritance, at least in a real-world context.

But take a deep breath and think twice. Actually, in the arena of object-based programming it isn't too difficult to understand how objects that belong to the same family can have different behaviors, even when they're using the same methods. And besides, there's an additional question that needs to be answered: how can this feature be used to create more efficient PHP applications?

As you can see, questions come up very quickly when it comes to taking advantage of Polymorphism in PHP. This implies that the subject in question deserves a closer look. Therefore, keeping in mind the interest you might have in how to get the most out of polymorphic objects in PHP 5, in this three part series, I'm going to take a deeper look at some concrete situations where Polymorphism can assists in developing more robust and efficient object-based applications.

More specifically speaking, in this first installment of the series, I'll be explaining how to implement Polymorphism to achieve a high level of abstraction when accessing different database systems. Subsequent articles will cover the use of polymorphic objects to build dynamic web documents and validate user-supplied input.

So, having established the topics that I plan to treat in this group of articles, let's get started now!



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