示例#1
0
        // Definicja książkowa
        //Tworzymy klasę adapter która implementuje interfejs IDuck, a indyka wstrzykujemy do niej przez konstruktor.
        //Dzięki takiemu zabiegowi można w klasie która z definicji jest kaczką (implementuje interfejs IDuck) podmienić zachowanie kwakania na
        //gęganie :)
        //public void Quack()
        //{
        //    _turkey.Gobble();
        //}

        private static void Main()
        {
            var turkey  = new WildTurkey();
            var adapter = new TurkeyAdapter(turkey);

            Tester(adapter);
        }
示例#2
0
        static void Main(string[] args)
        {
            var turkey  = new WildTurkey();
            var adapter = new TurkeyAdapter(turkey);

            Tester(adapter);
        }
示例#3
0
        static void Main(string[] args)
        {
/*      Aquí se crean el pato y el pavo, como puedes ver ambos implementan
 *      su propia interfaz con metodos como volar, graznar o gluglutear
 *
 *      Entra a las clases MallardDuck y WildTurkey
 */
            MallardDuck duck   = new MallardDuck();
            WildTurkey  turkey = new WildTurkey();

            //El adaptador convierte la interfaz de pato para ser utilizada por un pavo
            //sin problemas.

            //entra a la clase TurkeyAdapter
            IDuck turkeyAdapter = new TurkeyAdapter(turkey);

            //Aquí probaremos los métodos del pavo
            Console.WriteLine("The Turkey says...");
            turkey.Gobble();
            turkey.Fly();

            //Aquí probaremos los métodos del pato
            Console.WriteLine("\nThe Duck says...");
            TestDuck(duck);

            //Aquí probaremos los métodos el adaptador
            //(llamamos los metodos del pato pero se ejecutan como pavo)
            Console.WriteLine("\nThe TurkeyAdapter says...");
            TestDuck(turkeyAdapter);
            Console.ReadKey();
            //Ejecuta el proyecto para ver el resultado
            //Como podrás ver se pudo utilizar la interfaz de pato para llamar métodos
            //de un pavo y esto no afecto el funcionamiento
        }
示例#4
0
        static void Main(string[] args)
        {
            MallardDuck duck   = new MallardDuck();
            WildTurkey  turkey = new WildTurkey();

            TestDuck(duck);
            TestDuck(new TurkeyAdapter(turkey));
        }
示例#5
0
        static void Main(string[] args)
        {
            var turkey        = new WildTurkey();
            var turkeyAdapter = new TurkeyAdapter(turkey);

            turkeyAdapter.Fly();
            turkeyAdapter.Quack();
        }
示例#6
0
        private static void Main()
        {
            var turkey      = new WildTurkey();
            var duck        = new MallardDuck();
            var adapter     = new TurkeyAdapter(turkey);
            var duckadapter = new DuckAdapter(duck);

            Tester(adapter);
            Tester(duckadapter);
        }
示例#7
0
        private static void Main(string[] args)
        {
            var expected = "gobble gobble";

            WildTurkey turkey = new WildTurkey();

            TurkeyAdapter turkeyAdapter = new TurkeyAdapter(turkey);

            TestDuck(turkeyAdapter);

            Console.WriteLine(turkeyAdapter.Quack());
        }
        static void Main(string[] args)
        {
            var duck   = new MallardDuck();
            var turkey = new WildTurkey();

            var l = new List <IDuck>();

            l.Add(duck);
            l.Add(new TurkeyAdapter(turkey));

            foreach (var duckyDuck in l)
            {
                duckyDuck.Fly();
            }
        }
        static void DuckTestDrive()
        {
            IDuck duck          = new MallardDuck();
            var   turkey        = new WildTurkey();
            IDuck turkeyAdapter = new TurkeyAdapter(turkey);

            System.Console.WriteLine("Turkey says.........");
            turkey.Gobble();
            turkey.Fly();

            System.Console.WriteLine("Duck says.........");
            TestDuck(duck);

            System.Console.WriteLine("TurkeyAdapter says.........");
            TestDuck(turkeyAdapter);
        }
示例#10
0
        static void Main(string[] args)
        {
            MallardDuck duck          = new MallardDuck();
            WildTurkey  turkey        = new WildTurkey();
            IDuck       turkeyAdapter = new TurkeyAdapter(turkey);

            Console.WriteLine("The turkey says...");
            turkey.Gobble();
            turkey.Fly();

            Console.WriteLine("\nThe duck says...");
            TestDuck(duck);

            Console.WriteLine("\nThe adapted turkey says...");
            TestDuck(turkeyAdapter);
        }
示例#11
0
        static void Main(string[] args)
        {
            MallardDuck duck    = new MallardDuck();
            WildTurkey  turkey  = new WildTurkey();
            Duck        adapter = new TurkeyAdapter(turkey);

            Console.WriteLine("The turkey says...");
            turkey.Google();
            turkey.fly();
            Console.WriteLine("The duck says...");
            duck.quack();
            duck.fly();
            Console.WriteLine("The adapter says ...");
            adapter.quack();
            adapter.fly();
            Console.ReadKey();
        }
示例#12
0
        static void Main(string[] args)
        {
            var duck   = new MallardDuck();
            var turkey = new WildTurkey();

            var turkeyAdapter = new TurkeyAdapter(turkey);

            Console.WriteLine("The turkey says: ");
            turkey.Gobble();
            turkey.Fly();

            Console.WriteLine("\nThe Duck says: ");
            duck.Quack();
            duck.Fly();

            Console.WriteLine("\nThe turkeyAdapter says:");
            testDuck(turkeyAdapter);
        }
示例#13
0
        static void Main(string[] args)
        {
            MallardDuck duck   = new MallardDuck();
            WildTurkey  turkey = new WildTurkey();

            IDuck turkeyAdapter = new TrukeyAdapter(turkey);

            duck.Fly();
            duck.Quack();

            turkey.Fly();
            turkey.Gobble();

            turkeyAdapter.Fly();
            turkeyAdapter.Quack();

            Console.ReadKey();
        }
示例#14
0
        static void Main(string[] args)
        {
            MallardDuck duck   = new MallardDuck();
            WildTurkey  turkey = new WildTurkey();

            Console.WriteLine("The turkey says :");
            turkey.Gobble();
            turkey.Fly();

            Console.WriteLine("The duck says");
            duck.Quack();
            duck.Fly();

            TurkeyAdapter adapter = new TurkeyAdapter(turkey);

            adapter.Quack();
            adapter.Fly();
        }
        static void Main(string[] args)
        {
            var duck = new MallardDuck();

            var turkey        = new WildTurkey();
            var turkeyAdapter = new TurkeyAdapter(turkey);


            Console.WriteLine("The Turkey says...");
            turkey.Gobble();
            turkey.Fly();

            Console.WriteLine("The Duck says...");
            TestDuck(turkeyAdapter);

            var duckAdapter = new DuckAdapter(duck);

            TestTurkey(duckAdapter);
        }
示例#16
0
        static void Main(string[] args)
        {
            MallardDuck duck = new MallardDuck();

            WildTurkey turkey        = new WildTurkey();
            var        turkeyAdapter = new TurkeyAdapter(turkey);

            Console.WriteLine("The Turkey says.......");
            turkey.gobble();
            turkey.fly();

            Console.WriteLine("The Duck says.......");
            testDuck(duck);

            Console.WriteLine("The TurkeyAdapter says...");
            testDuck(turkeyAdapter);

            Console.ReadLine();
        }
示例#17
0
        static void Main(string[] args)
        {
            MallardDuck duck = new MallardDuck();

            WildTurkey turkey        = new WildTurkey();
            Duck       turkeyAdapter = new TurkeyAdapter(turkey);

            System.Console.WriteLine("The Turkey says...");
            System.Console.WriteLine(turkey.Gobble());
            System.Console.WriteLine(turkey.Fly());

            System.Console.WriteLine("\n The Duck says...");
            testDuck(duck);

            System.Console.WriteLine("\n The TurkeyAdapter says...");
            testDuck(turkeyAdapter);

            System.Console.ReadKey();
        }
示例#18
0
        static void Main(string[] args)
        {
            MallardDuck duck = new MallardDuck();

            WildTurkey turkey = new WildTurkey();
            var turkeyAdapter = new TurkeyAdapter(turkey);

            Console.WriteLine("The Turkey says.......");
            turkey.gobble();
            turkey.fly();

            Console.WriteLine("The Duck says.......");
            testDuck(duck);

            Console.WriteLine("The TurkeyAdapter says...");
            testDuck(turkeyAdapter);

            Console.ReadLine();
        }
示例#19
0
        static void Main(string[] args)
        {
            //Mallard duck is the target class which is derived from IDuck
            //WildTurkey is the adaptee derived from ITurkey
            //TurkeyAdapter is the adapter which adapts to IDuck which client knows so implements IDuck
            //But since the behaviour is of type WildTurkey an instance of  WildTurkey is passed in the constuctor.

            /*If we have a third party API and client does not know about these api's then we can come up with the class
             * which is derived from the class known to the client and provide a constructor which takes the third party API instance
             * Each of the methods in the known class will be modified to call the third pary api.*/

            Console.WriteLine("\nThis is Mallard actions:");
            IDuck mallardDuck = new MallardDuck();

            mallardDuck.Quack();
            mallardDuck.Fly();

            Console.WriteLine("\nThis is Wild Turkey actions:");
            ITurkey wildTurkey = new WildTurkey();

            wildTurkey.Gobble();
            wildTurkey.Fly();

\
            IDuck turkeyAdapter = new TurkeyAdapter(wildTurkey);

            Console.WriteLine("\nThis is Duck Adapter actions:");
            TestDuck(turkeyAdapter);


            DuckAdapter duckAdapter = new DuckAdapter(mallardDuck);

            Console.WriteLine("\nThis is Turkey Adapter actions:");
            TestDuck(duckAdapter);

            IDuck classAdapter = new ClassAdapter(wildTurkey);

            Console.WriteLine("\nThis is class Adapter actions:");
            TestDuck(classAdapter);

            Console.ReadLine();
        }