zoukankan      html  css  js  c++  java
  • 面向接口编程之惑 第二版

    刚才对面向接口充满了疑惑 经过自己的仔细推敲 加上 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();
              }

          }
    这个应该是面向接口的最终版本了 希望下个项目会用到这个啊  呵呵~~
  • 相关阅读:
    微信公众号开发的经验与坑
    微信公众号开发经验总结
    微信H5中禁止分享好友及分享到朋友圈的方法
    js 实现纯前端将数据导出excel两种方式,亲测有效
    JavaScript数组的一些方法、数学对象、定时器
    几种动态轨迹可视化效果实现方案-echarts、mapv、deck.gl
    前端大牛的博客收集
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/DrEdison/p/1246949.html
Copyright © 2011-2022 走看看