Home arrow PHP arrow Combining Interfaces and Abstract Classes to Build Polymorphs in PHP

Combining Interfaces and Abstract Classes to Build Polymorphs in PHP

In this fifth part of a seven-part series on building polymorphs in PHP 5, you will learn how to build a polymorph object by combining an abstract class and a simple interface. As you'll see, this object will be used for constructing basic HTML divs.

  1. Combining Interfaces and Abstract Classes to Build Polymorphs in PHP
  2. Achieving Polymorphism via abstract classes
  3. Defining a simple interface and an abstract class
  4. Building an improved polymorph class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
January 14, 2010

print this article



Without a doubt, understanding how to build polymorph objects in PHP 5 can be of great help when developing object-oriented web applications. this is especially true if you want to make use of the big pillars of software engineering in a truly efficient way.

In addition, itís quite possible that you, as a self-taught PHP developer, have already implemented Polymorphism in your own web-based programs without even knowing it. This is good; however, you should learn the theoretical concepts that surround the application of this key programming technique sooner or later in your career. This is especially true if your goal is to become a professional programmer.

Fortunately, in the case of PHP 5, Polymorphism can be achieved in a pretty straightforward fashion, even by those who have only an intermediate background in the object-oriented paradigm and the use of interfaces.

Naturally, if youíve already read all of the articles that precede this one, then hopefully at this point youíll have a solid background in how to build polymorph objects using interfaces and through abstract classes. In those tutorials I explained with a decent variety of code samples how to use Polymorphism for constructing objects that rendered some basic HTML elements, including divs and paragraphs.

However, one thing that must be noticed with reference to these examples is that they implemented Polymorphism through either interfaces or abstract classes, but never by utilizing both approaches at the same time. So, can this be done successfully? Fortunately, the answer is yes! Moreover, the process is so easy to accomplish that itís reduced to creating some subclasses from a base class, while making these children implementers of a certain interface. This is it.

In the next few lines Iím going to demonstrate how to work simultaneously with interfaces and abstract classes to implement Polymorphism in PHP 5.

Donít waste more time and begin reading right now!

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