为其他对象提供一种代理以控制对这个对象的访问.
Program.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace 代理模式
{
class Program
{
static void Main(string[] args)
{
SchoolGirl jiaojiao = new SchoolGirl();
jiaojiao.Name = "李娇娇";
Proxy daili = new Proxy(jiaojiao);
daili.GiveDolls();
daili.GiveFlowers();
daili.GiveChocolate();
Console.Read();
}
}
//送礼物
interface GiveGift
{
void GiveDolls();
void GiveFlowers();
void GiveChocolate();
}
class Proxy : GiveGift
{
Pursuit gg;
public Proxy(SchoolGirl mm)
{
gg = new Pursuit(mm);
}
public void GiveDolls()
{
gg.GiveDolls();
}
public void GiveFlowers()
{
gg.GiveFlowers();
}
public void GiveChocolate()
{
gg.GiveChocolate();
}
}
class Pursuit : GiveGift
{
SchoolGirl mm;
public Pursuit(SchoolGirl mm)
{
this.mm = mm;
}
public void GiveDolls()
{
Console.WriteLine(mm.Name + " 送你洋娃娃");
}
public void GiveFlowers()
{
Console.WriteLine(mm.Name + " 送你鲜花");
}
public void GiveChocolate()
{
Console.WriteLine(mm.Name + " 送你巧克力");
}
}
class SchoolGirl
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
}