Member-only story

C# Design Patterns: Template Method Design Pattern

SinghSharp
2 min readAug 28, 2021

--

What is Template Method Design Pattern?

In simple words, a template method design pattern is a behavioral design pattern that defines the basic skeleton (steps) of an algorithm. In this pattern, we can change the behavior of individual steps in the derived class but can not change the sequence by which each method will be called. We can understand it better by looking at the following example.

Real-world example

Let’s suppose that we have to make a burger and it requires some pre-defined steps. So the algorithm (steps) to make a burger is fixed but we can customize each step based on the burger we want to make. Basically, we have a standard procedure (a template) on how to make a burger.

Structural Code

We have a base class named MakeBurger.cs which contains all the basic steps that we need to perform to make a burger. It can have both abstract (when we don’t have default implementation) or virtual (when we have default implementation) methods based on the requirement.

--

--

SinghSharp
SinghSharp

Written by SinghSharp

A full-stack web developer passionate about software development, science and technology.

Responses (5)