示例#1
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);
        }
        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);
        }
示例#4
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);
        }
示例#5
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();
        }
示例#6
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();
        }
示例#7
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);
        }
示例#8
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();
        }
示例#9
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();
        }
示例#10
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();
        }
        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);
        }
示例#12
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();
        }
示例#13
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();
        }
示例#14
0
        static void Main(string[] args)
        {
            IDuck mallardDuck = new MallardDuck();

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

            ITurkey swedenTurkey = new SwedenTurkey();

            swedenTurkey.Fly();
            swedenTurkey.Gobble();

            TurkeyToDuckAdapter turkeyDisquisedAsDuck = new TurkeyToDuckAdapter(swedenTurkey);

            turkeyDisquisedAsDuck.Fly();
            turkeyDisquisedAsDuck.Quack();

            DuckToTurkeyAdapter duckDisquisedAsTurkey = new DuckToTurkeyAdapter(mallardDuck);

            duckDisquisedAsTurkey.Fly();
            duckDisquisedAsTurkey.Gobble();

            Console.ReadLine();
        }