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

            }
        }
    }
  • 相关阅读:
    【JAVA基础】String 类
    【Java基础】ArrayList类
    【Java基础】Scanner类
    【Java基础】类--------封装
    spring boot默认访问静态资源
    spring boot整合servlet、filter、Listener等组件方式
    在web项目中搭建一个spring mvc + spring + mybatis的环境
    spring mvc注解版01
    spring mvc简单介绍xml版
    服务器和客户端的理解
  • 原文地址:https://www.cnblogs.com/zzy0471/p/1349529.html
Copyright © 2011-2022 走看看