HomePHP 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.
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!