适配器模式

 

 

 

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    abstract class Birds
    {
        public abstract void Fly();

        public abstract void Shout();
    }

    class Duck:Birds
    {
        public override void Fly()
        {
            Console.WriteLine("鸭子飞");
        }

        public override void Shout()
        {
            Console.WriteLine("鸭子叫唤");
        }
    }

    class Chick:Birds
    {
        public override void Fly()
        {
            Console.WriteLine("小鸡飞");
        }

        public override void Shout()
        {
            Console.WriteLine("小鸡飞");
        }
    }

    class Adapter:Birds
    {
        private Eagle eagle=new Eagle();

        public override void Fly()
        {
            eagle.Fly();
        }

        public override void Shout()
        {
            eagle.Shout();
        }
    }

    class Eagle
    {
        public void Fly()
        {
            Console.WriteLine("老鹰飞");
        }

        public void Shout()
        {
            Console.WriteLine("老鹰叫唤");
        }
    }

    class Client
    {
        public static void Main()
        {
            Birds b = new Duck();
            b.Fly();
            b.Shout();
            b = new Chick();
            b.Fly();
            b.Shout();
            b = new Adapter();
            b.Fly();
            b.Shout();
            Console.Read();
        }
    }
}

posted on 2008-08-11 01:16  崔鹏飞  阅读(113)  评论(0编辑  收藏  举报

导航