Template method design pattern is a behavioural design pattern that is concerned with algorithms and the assignment of responsibilities between objects, as do all patterns that fall in this category. The speciality of behavioural design patterns is that they not only describe patterns of objects and classes but also the patterns of communication between them. You might have heard of encapsulating object creation, method invocation and other complex interfaces. What you might not have heard of is encapsulating algorithms. Template method design pattern is all about that. In this article, we will discuss what is Template method design pattern, why it is used, and a simple Template method design pattern java example to demonstrate its use case.

What is Template method design pattern?

Template method design pattern is a design pattern that provides an abstract definition of an algorithm with the help of an abstract method called Template Method. Like most of the behavioural design patterns, Template method design pattern uses inheritance to distribute behaviour between classes. In this pattern, each step invokes either an abstract or a primitive operation. A subclass provides additional details to the algorithm by defining the abstract operations. So, what is Template method design pattern’s intent? The intent is to define the skeleton of an algorithm by postponing some steps to subclasses i.e. it lets subclasses define certain steps of an algorithm in their own way keeping the structure of the algorithm intact.

#design-pattern #web-development

All you need to know about Template Method Design Pattern
1.30 GEEK