Csharp/C Sharp/Design Patterns/Strategy Pattern — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:38, 26 мая 2010
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();
}
}