Created
December 30, 2015 17:11
-
-
Save Naphier/5db3d52635f7361cfc9e to your computer and use it in GitHub Desktop.
Strategy Design Pattern Structure
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; | |
namespace StrategyPattern.structure | |
{ | |
abstract class Strategy | |
{ | |
public abstract void AlgorithmInterface(); | |
} | |
class ConcreteStrategyA : Strategy | |
{ | |
public override void AlgorithmInterface() | |
{ | |
Console.WriteLine("ConcreteStrategyA.AlgorithmInterface()"); | |
} | |
} | |
class ConcreteStrategyB : Strategy | |
{ | |
public override void AlgorithmInterface() | |
{ | |
Console.WriteLine("ConcreteStrategyB.AlgorithmInterface()"); | |
} | |
} | |
class ConcreteStrategyC : Strategy | |
{ | |
public override void AlgorithmInterface() | |
{ | |
Console.WriteLine("ConcreteStrategyC.AlgorithmInterface()"); | |
} | |
} | |
class Context | |
{ | |
private Strategy _strategy; | |
public Context(Strategy strategy) | |
{ | |
this._strategy = strategy; | |
} | |
public void ContextInterface() | |
{ | |
_strategy.AlgorithmInterface(); | |
} | |
} | |
class MainApp | |
{ | |
static void Main() | |
{ | |
Context context; | |
context = new Context(new ConcreteStrategyA()); | |
context.ContextInterface(); | |
context = new Context(new ConcreteStrategyB()); | |
context.ContextInterface(); | |
context = new Context(new ConcreteStrategyC()); | |
context.ContextInterface(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment