zoukankan      html  css  js  c++  java
  • adaptertheory.cs

      using System;
     
      // Adapter Pattern -  Simple                       Judith Bishop Aug 2006
      // Simplest adapter using interfaces and inheritance
     
      // Existing way requests are implemented
      class Adaptee {
        // Provide full precision
        public double SpecificRequest (double a, double b) {
          return a/b;
        }
      }
     
      // Required standard for requests
      interface ITarget {
        // Rough estimate required
        string Request (int i);
      }
     
      // Implementing the required standard via the Adaptee
      class Adapter : Adaptee, ITarget {
        public string Request (int i) {
          return "Rough estimate is " + (int) Math.Round(SpecificRequest (i,3));
        }
      }
     
      class Client {
        
        static void  Main () {
           // Showing the Adapteee in stand-alone mode
          Adaptee first = new Adaptee();
          Console.Write("Before the new standard\nPrecise reading: ");
          Console.WriteLine(first.SpecificRequest(5,3));
           
          // What the client really wants
          ITarget second = new Adapter();
          Console.WriteLine("\nMoving to the new standard");
          Console.WriteLine(second.Request(5));
        }
      }
  • 相关阅读:
    grub损坏修复方法
    基本命令(一)
    python 及 ipython 源码安装
    Samba服务安装配置
    shell语法一
    cacti监控软件
    Telnet服务安装及配置
    LVM逻辑卷,RAID磁盘阵列
    运维笔试题4(转载)
    运维笔试题3(转载)
  • 原文地址:https://www.cnblogs.com/shihao/p/2499944.html
Copyright © 2011-2022 走看看