Home arrow PHP arrow Abstract Classes in PHP: Setting Up a Concrete Example

Abstract Classes in PHP: Setting Up a Concrete Example

Welcome to part two of the series “Abstract classes in PHP.” In three tutorials, this series introduces the key concepts of abstract classes in PHP 4-PHP 5, and explores their application and use in different object-oriented development environments. Whether you’re an experienced PHP developer wanting to fill in some gaps related to abstract classes, or only a beginner starting to taste the power of object-based programming in PHP, hopefully you’ll find this series enjoyable and instructive.

  1. Abstract Classes in PHP: Setting Up a Concrete Example
  2. Setting up a concrete example: Defining the hierarchy of classes
  3. Deriving subclasses from the parent abstract class: defining the “resultProcessor” class
  4. More subclasses ahead: defining the “fileProcessor” class
  5. Assembling the pieces: putting the classes to work together
By: Alejandro Gervasio
Rating: starstarstarstarstar / 15
February 01, 2006

print this article




As you’ll probably recall, in the first article I thoroughly explained the key points for implementing abstract classes in PHP 4, and demonstrated different methods of using them within a PHP application. Since PHP 4 doesn’t offer true support for abstract classes, that is, classes that can’t (and shouldn’t) be instantiated, I went through the development of different approaches for preventing a specific class from direct instantiation. In accordance with this situation, I illustrated a few common approaches to prevent a class from being instantiated, ranging from including a “die()” statement inside the class constructor, to developing more polished techniques, such as utilizing a combination of the “get_class()” and “is_subclass()” PHP built-in functions.

As you know, this last method was also aimed at preventing a class from being instantiated from non child classes. This implies having a decent approach for using abstract classes, particularly in PHP 4 programming environments, where such classes aren’t natively supported.

Now, returning to this second installment of the series, and assuming that abstract classes aren’t foreign concepts to you any longer, I’ll go one step further in the corresponding learning curve.  I will set up a couple of more helpful examples, which I hope will serve as an introduction to using PHP 4 abstract classes in some concrete situations, something definitely much closer to the needs that most PHP developers have to face on a daily basis.

Right, having defined the objectives of this tutorial, it’s time to move on and learn how abstract classes can be put to work in some concrete situations. Let’s get started.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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