Exemplo n.º 1
0
        public static void Perform()
        {
            IBird    _sparrow = new Sparrow();
            IToyDuck _toyDuck = new PlasticToyDuck();
            // Wrap a bird in a birdAdapter so that it
            // behaves like toy duck
            IToyDuck _birdAdapter = new BirdAdapter(_sparrow);

            Console.WriteLine("Sparrow...");
            _sparrow.Fly();
            _sparrow.MakeSound();
            Console.WriteLine("Toy Duck");
            _toyDuck.Squeak();
            // bird behaving like a toy duck
            Console.WriteLine("BirdAdapter...");
            _birdAdapter.Squeak();
            Console.WriteLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("ADAPTOR DESIGN PATTERN\n");

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

            Bird           raven   = new Bird("Raven");
            PlasticToyDuck toyDuck = new PlasticToyDuck("Duck toy");

            // wrapper a bird into an adapter
            // in order to make a bird behave like a toyduck
            IToyDuck birdAdapter = new BirdAdapter(raven);

            raven.Fly();
            raven.MakeSound();

            toyDuck.Squeak();

            birdAdapter.Squeak();
        }