zoukankan      html  css  js  c++  java
  • 接口隔离原则

    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();//显示图表(编写时,使用接口调用自身包含的方法;运行时,调用子类所包含的方法)
    }

  • 相关阅读:
    盛最多水的容器
    寻找2个有序数组的中位数
    从链表中删除总和值为0的连续节点
    链表中的下一个更大节点
    链表的中间节点
    循环有序链表的插入
    设计链表
    链表组件
    扁平化多级双向链表
    将二叉搜索数转化为排序的双向链表
  • 原文地址:https://www.cnblogs.com/changbaishan/p/3265764.html
Copyright © 2011-2022 走看看