pursuedream
成功=水平+业务+沟通+判断
适配器

适配器要实现某一接口,也要实现某一类情况下使用。建立一个类,它继承该接口,继承一个类。
使用情况
1.系统需要使用现有的类,而此类的接口不符合系统的需要。

    public interface Itarget
    {
        void request();
    }

    public class Adapatee
    {
        public void Specific()
        {
            Console.WriteLine(" Adapatee ");
        }
    }
    //适配器
    public class Adapater : Adapatee, Itarget
    {
        public void request()
        {
            this.Specific();
        }
    }

//实现方式

public static void Main(string[] args)
{
    Itarget t=new Adapater();
    t.request();
}


或者:

   public class Target
    {
        public virtual void request();
    }

    public class Adapatee
    {
        public void Specific()
        {
            Console.WriteLine(" Adapatee ");
        }
    }

    //适配器

    public class Adapater : Target
    {
        Adapatee ad = new Adapatee();

        public override void request()
        {
            ad.Specific();
        }
    }


posted on 2007-06-25 15:23  pursuedream  阅读(200)  评论(0)    收藏  举报