コード例 #1
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();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ivpavici/HFDesignPatterns
        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);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: nandehutuzn/DesignPattern
        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();
        }
コード例 #4
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();
        }
コード例 #5
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();
        }