Tag Archives: wrapper

Understanding Polymorphism As Wrapper Class With PHP Example

Introduction

In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.
It able to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.
So it is overloading parent object. Child objects has all methods in their parent and childs can have more methods.

Several parent object type to support polymorphism are class, abstract and interface. In this post, I use ‘abstract’ class as parent to give polymorphism demo due to I will using it as wrapper class.
What I mean of wrapper class is I do not have to write same code over and over again in every child classes. I only have to write once in the abstract functions.
Abstract class can not have an instance or real object. It is only model of the class design but the different from ‘interface’ that abstract can have a body inside function declaration.

To explain the differences between abstract, interface and general class, look at code below: Continue reading