Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Strategy
- {
- class Program
- {
- static void Main(string[] args)
- {
- Context context;
- context = new Context(new ConcreteStrategyA());
- context.ContextInterface();
- context = new Context(new ConcreteStrategyB());
- context.ContextInterface();
- context = new Context(new ConcreteStrategyC());
- context.ContextInterface();
- Console.Read();
- }
- }
- abstract class Strategy
- {
- public abstract void AlgorithmInterface();
- }
- class ConcreteStrategyA : Strategy
- {
- public override void AlgorithmInterface()
- {
- Console.WriteLine("Algorithm A");
- }
- }
- class ConcreteStrategyB : Strategy
- {
- public override void AlgorithmInterface()
- {
- Console.WriteLine("Algorithm B");
- }
- }
- class ConcreteStrategyC : Strategy
- {
- public override void AlgorithmInterface()
- {
- Console.WriteLine("Algorithm C");
- }
- }
- class Context
- {
- Strategy strategy;
- public Context(Strategy strategy)
- {
- this.strategy = strategy;
- }
- public void ContextInterface()
- {
- strategy.AlgorithmInterface();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment