public static void Run()
        {
            Console.WriteLine("This real-world code demonstrates the Chain of Responsibility pattern in which several linked managers and executives can respond to a purchase request or hand it off to a superior. Each position has can have its own set of rules which orders they can approve.");
            Approver larry = new Director();
            Approver sam   = new VicePresident();
            Approver tammy = new President();

            larry.SetSuccessor(sam);
            sam.SetSuccessor(tammy);

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

            /*
             * Director Larry approved request# 2034
             * President Tammy approved request# 2035
             * Request# 2036 requires an executive meeting!
             */
        }
Пример #2
0
        static void Main(string[] args)
        {
            Approver director      = new Director();
            Approver vicePresident = new VicePresident();
            Approver president     = new President();

            director.SetSuccessor(vicePresident);
            vicePresident.SetSuccessor(president);

            Purchase purchaseOne = new Purchase()
            {
                Amount        = 24000,
                InvoiceNumber = 1,
                ItemName      = "Mobile"
            };

            Purchase purchaseTwo = new Purchase()
            {
                Amount        = 45000,
                InvoiceNumber = 2,
                ItemName      = "Motor Bike"
            };

            Purchase purchaseThree = new Purchase()
            {
                Amount        = 200000,
                InvoiceNumber = 3,
                ItemName      = "4K TV"
            };

            Purchase purchaseFour = new Purchase()
            {
                Amount        = 500000,
                InvoiceNumber = 4,
                ItemName      = "Car"
            };

            director.ProcessRequest(purchaseOne);
            director.ProcessRequest(purchaseTwo);
            director.ProcessRequest(purchaseThree);
            director.ProcessRequest(purchaseFour);

            Console.Read();
        }
Пример #3
0
        /// <summary>

        /// Entry point into console application.

        /// </summary>

        static void Main()
        {

            // 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);



            // Wait for user

            Console.ReadKey();

        }
Пример #4
0
        /// <summary>

        /// Entry point into console application.

        /// </summary>

        static void Main()
        {
            // 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);



            // Wait for user

            Console.ReadKey();
        }