zoukankan      html  css  js  c++  java
  • 设计模式学习之 代理模式

    /*
     * author:zzy
     * time:2008-12-7
     * describe: this is one simple example of proxy pattern;
     * when you can not invoke a subject directly (eg:remote WebService methed) or you can consider to use this pattern(Proxy)
     
    */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ProxyPattern
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    //client invoke
                Proxy proxy = new Proxy();
                Console.WriteLine(proxy.Sum(
    100,200));
                Console.ReadLine();

            }
        }


        
    interface Subject
        {
            
    int Sum(int one, int two);
        }

        
    /// <summary>
        
    /// real subject,provide functons
        
    /// </summary>
        class RealSbuject:Subject
        {
            
    public int Sum(int one, int two)
            {
                
    return one + two;
            }
        }

        
    /// <summary>
        
    /// proxy
        
    /// </summary>
        class Proxy : Subject
        {
            RealSbuject realSubject 
    = new RealSbuject();

            
    public int Sum(int one, int two)
            {
                
    //maybe can add some code here
                return this.realSubject.Sum(one,two);

            }
        }
    }
  • 相关阅读:
    微软职位内部推荐-Software Engineer II
    微软职位内部推荐-Senior Software Engineer
    Linux日期时间显示输出
    Redis性能优化
    Can't use Subversion command line client: svn
    redis常用性能分析命令
    Linux下配置tomcat + apr + native应对高并发
    Tomcat7并发和线程数
    mongodb常用命令小结
    Spring MVC @PathVariable被截断
  • 原文地址:https://www.cnblogs.com/zzy0471/p/1349529.html
Copyright © 2011-2022 走看看