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

            }
        }
    }
  • 相关阅读:
    sql 拼写
    五、URL Routing介绍
    六、防止JavaScript注入攻击
    七、创建自定义的HTML Helper
    二、理解Models,Views,Controllers
    一、使用ASP.NET MVC创建应用程序
    自己写的临时表应用
    四、理解视图层,视图数据和HTML辅助
    三、理解控制器、控制器动作和ActionResults
    Extensions (扩展)方法
  • 原文地址:https://www.cnblogs.com/zzy0471/p/1349529.html
Copyright © 2011-2022 走看看