The Template Method Pattern defines the framework for executing certain algorithms. An abstract class publicly defines the way or template to execute its methods, and its subclasses can override methods as needed or call them in the way defined in the abstract class. This type of design pattern falls under the category of behavioral patterns.
The Template Method Pattern is a behavioral design pattern used to define the framework of an algorithm in an operation, thus deferring some steps to subclasses, which can redefine certain steps of the algorithm without changing its structure.
classBuilder{build(){this.start();this.lint();this.assemble();this.deploy();}}classAndroidBuilderextendsBuilder{constructor(){super();}start(){ console.log("Ready to start build android");}lint(){ console.log("Linting the android code");}assemble(){ console.log("Assembling the android build");}deploy(){ console.log("Deploying android build to server");}}classIosBuilderextendsBuilder{constructor(){super();}start(){ console.log("Ready to start build ios");}lint(){ console.log("Linting the ios code");}assemble(){ console.log("Assembling the ios build");}deploy(){ console.log("Deploying ios build to server");}}(function(){const androidBuilder =newAndroidBuilder(); androidBuilder.build();// Ready to start build android// Linting the android code// Assembling the android build// Deploying android build to serverconst iosBuilder =newIosBuilder(); iosBuilder.build();// Ready to start build ios// Linting the ios code// Assembling the ios build// Deploying ios build to server})();