Skip to content

Instantly share code, notes, and snippets.

@rbwestmoreland
Created January 25, 2012 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbwestmoreland/1674182 to your computer and use it in GitHub Desktop.
Save rbwestmoreland/1674182 to your computer and use it in GitHub Desktop.
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