Template Design pattern

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

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.