• 面向接口编程之惑 第二版


    刚才对面向接口充满了疑惑 经过自己的仔细推敲 加上 Vs 的智能提示 终于找到解决方法了 放代码出来啊 如果你刚看过那篇 你应该很清楚了啊

     class Program
        
    {
            
    static void Main(string[] args)
            
    {
                Computeruse com 
    = new Computeruse();
                Adult me 
    = new Adult();
                me.UseComputer(com);
                Child mybrother 
    = new Child();
                mybrother.UseComputer(com);
                Console.ReadLine();
            }

        }

        
    class Computeruse : IFinal
        
    {
            
    public Computeruse()
            
    {
                Console.WriteLine(
    "这个电脑我在用 别管我干嘛!!");
            }

            
    IFinal 成员
        }

        
    interface IFinal
        
    {
            
    void ToLearn();
            
    void ToWork();
            
    void ToFun();
        }

        
    interface IComputerLearn:IFinal
        
    {
            
    void ToLearn();
        }

        
    interface IComputerWork:IFinal
        
    {
            
    void ToWork();
        }

        
    interface IComputerToFun:IFinal
        
    {
            
    void ToFun();
        }

        
    class Adult
        
    {
          
    public void UseComputer(IFinal IFinal)
          
    {
              IFinal.ToLearn();
              IFinal.ToFun();
          }

        }

          
    class Child
          
    {
              
    public void UseComputer( IFinal IFinal)
              
    {
                  IFinal.ToFun();
              }

          }
    这个应该是面向接口的最终版本了 希望下个项目会用到这个啊  呵呵~~
  • 相关阅读:
    CSS3 object-fit 图像裁剪
    jQuery.extend 使用函数
    ios 不支持iframe 解决方案
    详解HTML5中rel属性的prefetch预加载功能使用
    web页面加载、解析、渲染过程
    TCP的三次握手(建立连接)与 四次挥手(关闭连接)
    html---规范、细节积累-01
    pio设置单元格式
    让一个数字显示指定位数
    linux下获取微秒级精度的时间
  • 原文地址:https://www.cnblogs.com/DrEdison/p/1246949.html
Copyright © 2020-2023  润新知