Template Method Quickly

I have always wondered a very easy bare minimum way of remembering and explaining design patterns. For someone who has ever written a test case using XUnit or has ever worked with servlets, it is so easy to explain about Template Method pattern. Let us quickly go through the checkllist of template method pattern

1. Define a new abstract base class to host the skeleton of an algorithm.
2. Move the definition of all standard steps to this new base class.
3. Define a placeholder or “hook” method in the base class for each step that requires many different implementations.
4. Invoke the hook method(s) from the template method.
5. Each of the existing classes declares an “is-a” relationship to the new abstract base class.
6. The only details that is in the sub classes will be the implementation details peculiar to each derived class.

This is exactly what happens when we extend a TestCase to create XUnit test cases as there is a common set of steps to be followed setup stuff for the test case, run the test case and then cleanup, so the template method will look something like this

public void execute() {
setUp();
runTest();
tearDown();
}