• 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));
        }
      }
  • 相关阅读:
    【hdu4285】 circuits
    java代码获取ip地址
    java覆写hashcode方法
    java覆写equals方法
    Linux下Apache服务器并发优化
    异常:cvc-complex-type.2.4.a: Invalid content was found starting with element
    SpringMVC请求访问不到静态文件解决方式
    mina教程
    分布式session
    jsp自定义标签
  • 原文地址:https://www.cnblogs.com/shihao/p/2499944.html
Copyright © 2020-2023  润新知