Created
January 25, 2012 02:11
-
-
Save rbwestmoreland/1674182 to your computer and use it in GitHub Desktop.
Properly Implementing the Template Method Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class ConcreteTemplateA : Template | |
{ | |
protected override void DoThis() | |
{ | |
// Do this | |
} | |
protected override void DoThat() | |
{ | |
// Do that | |
} | |
protected override void DoOther() | |
{ | |
// Do other | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class ConcreteTemplateB : Template | |
{ | |
protected override void DoThis() | |
{ | |
// Do this | |
} | |
protected override void DoThat() | |
{ | |
// Do that | |
} | |
protected override void DoOther() | |
{ | |
// Do other | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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