Template Design Pattern

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
60; -GOF Design Patterns

In Template design pattern, an abstract class wraps some defined ways to its method. That method allows you to override parts of the method without rewriting it. You could use its concrete class to your application to perform similar type actions. This design pattern comes under the Behavior design pattern family of GOF pattern.

There are following lists the benefits of using the Template pattern:

  • It reduces the boilerplate codes in the application by reusing code.
  • This pattern creates a template or way to reuse multiple similar algorithms to perform some business requirements.

Let's see the following UML diagram is showing the components of Template design pattern:

UML Diagram for Template design pattern
  • AbstractClass: This is an abstract class that contains a template method defining the skeleton of an algorithm.
  • ConcreteClass: This is a concrete subclass of AbstractClass that implements the operations to carry out the algorithm-specific primitive steps.

Let's see the next section about J2EE design patterns in the enterprise distributed applications

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset