Template Design pattern
In this pattern basic algorithm is defined in abstract class. Then the subclass can override the functions to change the behaviors.
Example:
We take human as an example.Here Human is abstract class.
The human can classified as with the type of work that human doing.Example as Doctor, Engineer and etc.
abstract class Human {
public final function walk() {
echo “walking”;
}
public final function eat() {
echo “eating”;
}
abstract void work(){
}
}
Doctor class
class Doctor extends Human {
public void work(){
echo “some work1″;
}
}
class Doctor extends Engineer {
public void work(){
echo “some work1″;
}
}
So in the above example abstract class contains the basic functions human can do.Based on our classifications we can override the function which are defined in the abstract class.
Usage
1. Avoiding duplication of coding
2. can control the sub class
