Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Leaf apple     = new Leaf("苹果", 5);
            Leaf banana    = new Leaf("香蕉", 2);
            Leaf pineapple = new Leaf("菠萝", 20);
            Leaf pear      = new Leaf("梨", 4);

            Composite red   = new Composite("红袋子");
            Composite blue  = new Composite("蓝袋子");
            Composite black = new Composite("黑袋子");

            red.ADD(apple);
            red.ADD(banana);

            blue.ADD(pineapple);
            blue.ADD(apple);
            blue.ADD(pear);

            black.ADD(red);
            black.ADD(blue);
            black.ADD(pear);
            Console.WriteLine("总价" + black.Charge());
        }