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();
              }

          }
    这个应该是面向接口的最终版本了 希望下个项目会用到这个啊  呵呵~~
  • 相关阅读:
    rapidjson 使用
    【设计模式】模板方法模式
    【设计模式】策略模式
    【设计模式】建造者模式
    【设计模式】享元模式
    /dev/sda1 contains a file system with errors,check forced.
    如何编写高效的Python的代码
    VsCode 调试 Python 代码
    Python 使用 pyinstaller 打包 代码
    初次使用git上传代码到github远程仓库
  • 原文地址:https://www.cnblogs.com/DrEdison/p/1246949.html
Copyright © 2011-2022 走看看