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

        }
    }
}

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-06-24
  • 2021-10-24
  • 2022-01-10
猜你喜欢
  • 2021-12-14
  • 2021-10-31
  • 2022-01-02
  • 2021-06-05
  • 2021-11-26
  • 2021-07-05
  • 2021-07-05
相关资源
相似解决方案