Exemplo n.º 1
0
        static void Main(string[] args)
        {
            MallardDuck duck   = new MallardDuck();
            WildTurkey  turkey = new WildTurkey();

            IDuck turkeyAdapter = new TurkeyAdapter(turkey);

            Console.WriteLine("\t---Turkey!!!---");
            turkey.Fly();
            turkey.Gobble();
            // Ошибка так как Turkey реализует интерфейс ITurkey
            //TestDuck(turkey);
            TestDuck(turkeyAdapter);

            Console.WriteLine("\n\t---Duck!!!---");
            duck.Fly();
            duck.Quack();

            Console.WriteLine("\t---Turkey!!!---");
            TestDuck(turkeyAdapter);

            Console.WriteLine("\n\t---Duck!!!---");
            TestDuck(duck);

            Console.WriteLine("\n\t---Duck!!!---");
            ITurkey duckAdapter = new DuckAdapter(duck);

            duckAdapter.Fly();
            duckAdapter.Gobble();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            IDuck duck = new MallardDuck();

            duck.Fly();
            duck.Quack();
            Console.WriteLine();

            ITurkey turkey = new WildTurkey();

            turkey.Fly();
            turkey.Gobble();
            Console.WriteLine();

            IDuck adapterDuck = new TurkeyAdapter(turkey);

            adapterDuck.Fly();
            adapterDuck.Quack();
            Console.WriteLine();

            ITurkey adapterTurkey = new DuckAdapter(duck);

            adapterTurkey.Fly();
            adapterTurkey.Gobble();

            Console.ReadKey();
        }
 static void Main(string[] args)
 {
     var turkey = new WildTurkey();
     var duck = new DuckAdapter(turkey);
     duck.Sing();
     duck.Fly();
 }
        public void TestDuckAdapter()
        {
            Duck   mallard     = new MallardDuck();
            Turkey duckAdapter = new DuckAdapter(mallard);

            Assert.AreEqual("Quack", duckAdapter.Gobble());
            Assert.AreEqual("I'm flying", duckAdapter.Fly());
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var turkey = new WildTurkey();
            var duck   = new DuckAdapter(turkey);

            duck.Sing();
            duck.Fly();
        }
        public void DuckAdapterTest()
        {
            MallardDuck duck        = new MallardDuck();
            ITurkey     duckAdapter = new DuckAdapter(duck);

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("The DuckAdapter says...");
                duckAdapter.Gobble();
                duckAdapter.Fly();
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            IDog  dog  = new WildDog();
            IDuck duck = new WildDuck();

            dog.Bark();
            duck.Quack();
            dog.Jump();
            duck.Fly();
            DuckAdapter adapterDuck = new DuckAdapter(dog);

            adapterDuck.Quack();
            adapterDuck.Fly();
        }
Exemplo n.º 8
0
        static void Adapter()
        {
            Console.WriteLine("Duck:");
            Adapter.Classes.Duck duck = new Adapter.Classes.Duck();
            duck.Quack();
            duck.Fly();
            Console.WriteLine();

            Console.WriteLine("Turkey:");
            Turkey turkey = new Turkey();

            turkey.Gobble();
            turkey.Fly();
            Console.WriteLine();

            Console.WriteLine("DuckAdapter:");
            DuckAdapter duckAdapter = new DuckAdapter(turkey);

            duckAdapter.Quack();
            duckAdapter.Fly();
        }