forked from AmazingCode/DesignModel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7、代理模式.cs
53 lines (51 loc) · 1.4 KB
/
7、代理模式.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
/// <summary>
/// 什么是代理模式:本来有一个类A可以直接执行自己的方法就可以实现一个功能,现在先将这个类A作为一个属性传递给一个代理类,代理类在通过自己的方法调用A对象的方法,同时可以添加一些新的功能
/// 为其他对象提供一种代理,用来控制对这个对象的访问。
/// </summary>
class _7_代理模式
{
public void Main()
{
}
}
public interface IGiveGift
{
void GiveDolls();
void GiveFlowers();
}
public class Pursuit:IGiveGift
{
public void GiveDolls()
{
Console.Write("Give Dolls");
}
public void GiveFlowers()
{
Console.Write("Give Flowers");
}
}
public class Proxy:IGiveGift
{
private IGiveGift IGift;
public Proxy(IGiveGift iGift)
{
this.IGift = iGift;
}
public void GiveDolls()
{
IGift.GiveFlowers();
Console.WriteLine("proxy can do some badthing in this lol");
}
public void GiveFlowers()
{
IGift.GiveFlowers();
Console.WriteLine("hello beauty,the flower is mine,not his");
}
}
}