Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Properly Implementing the Template Method Pattern
using System;
public class ConcreteTemplateA : Template
{
protected override void DoThis()
{
// Do this
}
protected override void DoThat()
{
// Do that
}
protected override void DoOther()
{
// Do other
}
}
using System;
public class ConcreteTemplateB : Template
{
protected override void DoThis()
{
// Do this
}
protected override void DoThat()
{
// Do that
}
protected override void DoOther()
{
// Do other
}
}
using System;
/// <summary>
/// An example Template Method pattern.
/// <para>The Template Method pattern is a behavioral
/// design pattern, whose purpose is to define the
/// skeleton of an algorithm in an operation, deferring
/// some steps to subclasses.</para>
/// </summary>
public abstract class Template
{
public void Process()
{
DoThis();
DoThat();
DoOther();
}
protected abstract void DoThis();
protected abstract void DoThat();
protected abstract void DoOther();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.