Exemple #1
0
        static void Main(string[] args)
        {
            Person p = new Doctor("薇薇");
            ClothesA cA = new ClothesA();
            cA.SetComponent(p);
            ClothesB cB = new ClothesB();
            cB.SetComponent(cA);
            ClothesC cC = new ClothesC();
            cC.SetComponent(cB);
            cC.Wear();

            Console.WriteLine("-------------------");

            Person p2 = new Teacher("Bob");
            cB.SetComponent(p2);
            cC.SetComponent(cB);
            cA.SetComponent(cC);
            cA.Wear();
            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Person   p  = new Doctor("薇薇");
            ClothesA cA = new ClothesA();

            cA.SetComponent(p);
            ClothesB cB = new ClothesB();

            cB.SetComponent(cA);
            ClothesC cC = new ClothesC();

            cC.SetComponent(cB);
            cC.Wear();

            Console.WriteLine("-------------------");

            Person p2 = new Teacher("Bob");

            cB.SetComponent(p2);
            cC.SetComponent(cB);
            cA.SetComponent(cC);
            cA.Wear();
            Console.ReadLine();
        }