public static void TestChainOfResp() { Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { var handler = h1.HandleRequest(request, true); if (request >= 0 && request < 10) { Assert.AreEqual(h1, handler); } else if (request >= 10 && request < 20) { Assert.AreEqual(h2, handler); } else { Assert.AreEqual(h3, handler); } } }
public void ChainOfResponsibilityUsage() { Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } }
static void Main(string[] args) { Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } Console.ReadKey(); }
public void StructuralTest() { Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } }
void Start() { // Setup Chain of Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } }
static void Main(string[] args) { //职责链模式 Handler handler1 = new ConcreteHandler1(); Handler handler2 = new ConcreteHandler2(); Handler handler3 = new ConcreteHandler3(); handler1.SetSuccessor(handler2); handler2.SetSuccessor(handler3); int[] request = { 2, 6, 10, 15, 18, 20, 28, 29, 8, 5, 4 }; foreach (int item in request) { handler1.HandleRequest(item); } Console.WriteLine("*****************************************"); CommonManager jingli = new CommonManager("金立"); Majordomo zongjian = new Majordomo("张无忌"); GeneraManager zongjingli = new GeneraManager("张三丰"); jingli.SetSuperior(zongjian); zongjian.SetSuperior(zongjingli); jingli.RequestApploactions(new Request { Number = 1, RequestType = "请假", RequestContent = "请假一天" }); jingli.RequestApploactions(new Request { Number = 10, RequestType = "请假", RequestContent = "请假一天" }); jingli.RequestApploactions(new Request { Number = 500, RequestType = "加薪", RequestContent = "请求加薪" }); jingli.RequestApploactions(new Request { Number = 1000, RequestType = "加薪", RequestContent = "请求加薪" }); Console.Read(); }
static void Main(string[] args) { // Setup Chain of Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } // Wait for user Console.Read(); }
/// <summary> /// Entry point into console application. /// </summary> static void Main() { // Setup Chain of Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } // Wait for user Console.ReadKey(); }
private static void callChainOfResponsibility() { Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.handleRequest(request); } // Wait for user Console.ReadKey(); }
static void ChainOfResponsibilityTester() { #region sample 1 // Setup Chain of Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } #endregion #region sample 2 // Setup Chain of Responsibility Approver larry = new Director(); Approver sam = new VicePresident(); Approver tammy = new President(); larry.SetSuccessor(sam); sam.SetSuccessor(tammy); // Generate and process purchase requests Purchase p = new Purchase(2034, 350.00, "Assets"); larry.ProcessRequest(p); p = new Purchase(2035, 32590.10, "Project X"); larry.ProcessRequest(p); p = new Purchase(2036, 122100.00, "Project Y"); larry.ProcessRequest(p); #endregion }
// Entry point into console application. static void Main() { // Setup Chain of Responsibility (top-down) Handler h4 = new ConcreteHandler4(); Handler h3 = new ConcreteHandler3(h4); Handler h2 = new ConcreteHandler2(); Handler h1 = new ConcreteHandler1(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate requests int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20, 3, 35, 50, 39, 42, 32 }; // Process requests foreach (int request in requests) { h1.HandleRequest(request); } // Wait for user Console.ReadKey(); }
// Entry point into console application. static void Main() { // Setup Chain of Responsibility (top-down) Handler h4 = new ConcreteHandler4(); Handler h3 = new ConcreteHandler3(h4); Handler h2 = new ConcreteHandler2(); Handler h1 = new ConcreteHandler1(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate requests int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20, 3, 35, 50, 39, 42, 32 }; // Process requests foreach (int request in requests) h1.HandleRequest(request); // Wait for user Console.ReadKey(); }
//static Memento memento; //static string path = @"D:\text.txt"; static void Main(string[] args) { //var context = new Context(); //var list = new List<AbstractExpression>(); //list.Add(new TerminalExpression()); //list.Add(new NonterminalExpression()); //list.Add(new TerminalExpression()); //list.Add(new TerminalExpression()); //foreach (AbstractExpression exp in list) //{ // Console.WriteLine(exp.Interpret(context)); //} //// MEMENTO //File.WriteAllText(path,"pierwszy tekst"); //if (path != ""&& File.Exists(path)) //{ // memento = new Memento(path, File.ReadAllBytes(path)); //} //File.WriteAllText(path, "drugi tekst"); //memento.RevertFromMemento(); //File.WriteAllText(path, "trzeci tekst(do zapamietania)"); //memento.SetNewData(path); //File.WriteAllText(path, "czwarty tekst"); //memento.RevertFromMemento(); //STATE //var small = new SmallState(); //Contextt context = new Contextt(small); //Console.Read(); //context.Change(); //Console.Read(); //context.Change(); //Console.Read(); //context.Change(); ////STRATEGY //bool onceAgain = true; //while (onceAgain) //{ // Console.WriteLine("Wybierz postać: A,B,C"); // Console.WriteLine(); // ConsoleKeyInfo figure = Console.ReadKey(true); // IFigure ifigure = null; // switch (figure.Key) // { // case ConsoleKey.A: // ifigure = new Figure1(); // break; // case ConsoleKey.B: // ifigure = new Figure2(); // break; // case ConsoleKey.C: // ifigure = new Figure3(); // break; // } // Console.WriteLine($"Wybrałes postać: { figure.Key}"); // Console.WriteLine(ifigure.Kopnięcie()[0]); // Console.WriteLine(ifigure.Uderzenie()[0]); // Console.WriteLine(); // onceAgain = true; //} //ITERATOR //ConcreteIterable concreteIterable = new ConcreteIterable(); //concreteIterable[0] = 1; //concreteIterable[1] = 2; //concreteIterable[2] = 3; //IIterator iterator = concreteIterable.GetIterator(); //Console.WriteLine(iterator.First()); //while(!iterator.IsEnd()) //{ // Console.WriteLine(iterator.Next()); //} // OBSERVATOR //ConcreteSubject concreteSubject = new ConcreteSubject(); //concreteSubject.Attach(new ConcreteObserver(concreteSubject, "Pierwszy")); //concreteSubject.Attach(new ConcreteObserver(concreteSubject, "Drugi")); //var third = new ConcreteObserver(concreteSubject, "trzeci"); //concreteSubject.Attach(third); //concreteSubject.SubjectState = "Super stan"; //concreteSubject.Notify(); //concreteSubject.Detach(third); //concreteSubject.Notify(); //Chain Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); int[] request = { 1, 2, 3, 10, 11, 22, 25 }; foreach (var item in request) { h3.HandleRequest(item); } Console.Read(); }