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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


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

Dev Shed Tutorial Topics: