Материал из .Net Framework эксперт
Strategy Pattern Demo
using System;
public abstract class Strategy {
public abstract void CreditBusinessRule();
public Strategy() { ;}
}
public class AStrategy : Strategy {
public override void CreditBusinessRule() {
Console.WriteLine("A");
}
public AStrategy() { ;}
}
public class BStrategy : Strategy {
public override void CreditBusinessRule() {
Console.WriteLine("Manager");
}
public BStrategy() { }
}
public class MyContext {
Strategy aStrategy;
public MyContext(Strategy crStrategy) {
this.aStrategy = crStrategy;
}
public void BusinessRule() {
this.aStrategy.CreditBusinessRule();
}
}
class Client {
static void Main(string[] args) {
MyContext cr = new MyContext(new AStrategy());
cr.BusinessRule();
}
}