예제 #1
0
        public void TestMethod1()
        {
            CoinHandlerBase h5   = new FivePenceHandler();
            CoinHandlerBase h10  = new TenPenceHandler();
            CoinHandlerBase h20  = new TwentyPenceHandler();
            CoinHandlerBase h50  = new FiftyPenceHandler();
            CoinHandlerBase h100 = new OnePoundHandler();

            h5.SetSuccessor(h10);
            h10.SetSuccessor(h20);
            h20.SetSuccessor(h50);
            h50.SetSuccessor(h100);

            Coin tenPence = new Coin {
                Diameter = 24.49F, Weight = 6.5F
            };
            Coin fiftyPence = new Coin {
                Diameter = 27.31F, Weight = 8.01F
            };
            Coin counterfeitPound = new Coin {
                Diameter = 22.5F, Weight = 9F
            };

            h5.HandleCoin(tenPence);
            h5.HandleCoin(fiftyPence);
            h5.HandleCoin(counterfeitPound);
        }
예제 #2
0
        static void Main()
        {
            var h5   = new FivePenceHandler();
            var h10  = new TenPenceHandler();
            var h20  = new TwentyPenceHandler();
            var h50  = new FiftyPenceHandler();
            var h100 = new OnePoundHandler();

            h5.SetSuccessor(h10);
            h10.SetSuccessor(h20);
            h20.SetSuccessor(h50);
            h50.SetSuccessor(h100);

            var tenPence = new Coin {
                Diameter = 24.49F, Weight = 6.5F
            };
            var fiftyPence = new Coin {
                Diameter = 27.31F, Weight = 8.01F
            };
            var counterfeitPound = new Coin {
                Diameter = 22.5F, Weight = 9F
            };

            Console.WriteLine(h5.EvaluateCoin(tenPence));
            Console.WriteLine(h5.EvaluateCoin(fiftyPence));
            Console.WriteLine(h5.EvaluateCoin(counterfeitPound));
        }