-
what is the template method pattern
-
The template Method is used prominently in frameworks. Each framework implements the invariant pieces of a domain’s architecture and defines “placeholders” for all necessary or interesting client customization options. In so doing, the framework becomes the “centre of the universe”, and the client customizations are simply “the third rock from the sun”. This inverted control structure has been affectionately labeled “the Hollywood principle” - “don’t call us, we’ll call you”.
-
In plain words: The template method defines the skeleton of how a certain algorithm could be performed but defers the implementation of those steps to the children’s classes.
-
Wikipedia says
In software engineering, the template method pattern is a behavioral design pattern that defines the program skeleton of an algorithm in an operation, deferring some steps to subclasses. It lets one redefine certain steps of an algorithm without changing the algorithm’s structure.
Programmatic Example
Imagine we have a build tool that helps us test, lint, build, generate build reports (i.e. code coverage reports, linting report etc) and deploy our app on the test server.
First of all we have our base class that specifies the skeleton for the build algorithm
Then we can have our implementations
And then it can be used as