Select Page

Template method

Template method

Defines the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses refine certain steps of an algorithm without changing the algorithm’s structure.

Source Code

/**  
* This class defines abstract primitive operations that concrete
* subclasses define to implement steps of an algorithm. Implements a template
* method defining the skeleton of an algorithm.
*
* @role __TemplateContext */ public abstract class Context { /**
* Primitive operation.
*/ public abstract void doPrimitiveOperation(); /**
* Defines the skeleton of an algorithm. Calls primitive operations as well
* as operations defined in AbstractClass or those in other objects.
*/ public void templateMethod() { // put your code here doPrimitiveOperation(); // put your code here } } /**
* Implements the primitive operations to carry out subclass-specific steps of
* the algorithm.
*/ public class ConcreteClass extends Context { /**
@see patterns.gof.templatemethod.Context#doPrimitiveOperation()
*/ public void doPrimitiveOperation() { // provide implementation here } }

Template 

About The Author

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories