Strategy Pattern Demo : Strategy Pattern : Design Patterns C# Source Code


Custom Search

C# Source Code » Design Patterns » Strategy Pattern »

 

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();
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Design Patterns
» Strategy Pattern