设计模式学习之 代理模式
/*
* 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);
}
}
}
* 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);
}
}
}
欢迎转载,转载请注明出处