Design Patterns Template Pattern - Design Patterns

What is Design Patterns Template Pattern?

In Template pattern, a summary class expose define way(s)/template(s) to execute its methods. Its subclasses can override the way implementation as per need but the invocation is to be in the same way as define by an abstract class. This pattern comes under behaviour pattern group.


We are going to make a Game concrete class defining operations with a template method set to be finishing so that it cannot be override. Cricket and Football are concrete classes that expand Game and override its methods.

TemplatePatternDemo, our demo class, will use Game to express use of template pattern.

Step 1

Create an abstract class with a template method being finishing.

Step 2

Create concrete classes extend the beyond class.

Step 3

Apply the Game's template method play () to express a define way of playing game.

Step 4

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Design Patterns Topics