接口隔离原则

Interface IDataHandler
{
    void DataRead();
}

Interface IXMLTransformer
{
    void TransformToXML();
}

Interface ICharHandler
{
    void CreateChar();
    void DisplayChar();
}

Interface IReportHandler
{
    void Createreport();
    void Displayreport();
}

public class ConcreteClass:IDataHandler,ICharHandler  //实现两个接口,相当于有两个“基类”
{
    public void DataRead(){.......}
    public void CreateChar(){......}
    public void DisplayChar(){......}
}


//Client,消费端
public void main(string[] strs)
{
    //创建子类的实例
    ConcreteClass conClass = new ConcreteClass();
    //把子类的实例赋值给“基类”的引用
    IDataHandler idh = conClass;
    idh.DataRead(); //读取数据(编写时,使用接口调用自身包含的方法;运行时,调用子类所包含的方法)
    //把子类的实例赋值给“基类”的引用
    ICharHandler ich = conClass;
    ich.CreateChar();//绘制图表(编写时,使用接口调用自身包含的方法;运行时,调用子类所包含的方法)
    ich.DisplayChar();//显示图表(编写时,使用接口调用自身包含的方法;运行时,调用子类所包含的方法)
}

posted @ 2013-08-18 11:18  长白山  阅读(193)  评论(0编辑  收藏  举报