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));
        }
      }
  • 相关阅读:
    用JavaDoc生成项目文档
    thymeleaf参考手册
    转的一个Java基本功
    杂记
    修改Esxi克隆的CentOS的IP地址
    CentOS搭建socket5代理服务器
    CentOS上搭建Nginx + Mono 运行 asp.net
    启动PPT的时候一直配置vs2013的问题解决
    swift 元组
    swift 集合类型(二)
  • 原文地址:https://www.cnblogs.com/shihao/p/2499944.html
Copyright © 2011-2022 走看看