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.

Implementation

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.
template_pattern_uml_diagram

Step 1

Create an abstract class with a template method being finishing.

Game.java

Step 2

Create concrete classes extend the beyond class.

Cricket.java

Football.java

Step 3

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

TemplatePatternDemo.java

Step 4

Verify the output.

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

Design Patterns Topics