![](https://i-blog.csdnimg.cn/blog_migrate/2dabe605212384b3ad2614302e32b6a9.png)
abstract class Subject
{
public abstract void Request();
}
//本体
class RealSubject : Subject
{
public override void Request()
{
Console.WriteLine("真实的请求");
}
}
//代理
class Proxy : Subject
{
RealSubject realSubject;
public override void Request()
{
if(realSubject==null)
{
realSubject = new RealSubject();
}
realSubject.Request();
}
}
//主函数
class Program
{
static void Main(string[] args)
{
Proxy proxy = new Proxy();
proxy.Request();
}
}
//女孩
class SchoolGirl
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
//送礼物接口
interface GiveGift
{
void GiveDolle();
void GiveFlowers();
void GiveChocolate();
}
//追求者
class Pursuit:GiveGift
{
SchoolGirl mm;
public Pursuit(SchoolGirl mm)
{
this.mm = mm;
}
public void GiveDolle()
{
Console.WriteLine(mm.Name + " 送你洋娃娃");
}
public void GiveFlowers()
{
Console.WriteLine(mm.Name + " 送你鲜花");
}
public void GiveChocolate()
{
Console.WriteLine(mm.Name + " 送你巧克力");
}
}
//代理人
class Proxy:GiveGift
{
Pursuit gg;
public Proxy(SchoolGirl mm)
{
gg = new Pursuit(mm);
}
public void GiveChocolate()
{
gg.GiveChocolate();
}
public void GiveDolle()
{
gg.GiveDolle();
}
public void GiveFlowers()
{
gg.GiveFlowers();
}
}
//主函数
class Program
{
static void Main(string[] args)
{
SchoolGirl jj = new SchoolGirl();
jj.Name = "娇娇";
Proxy daili = new Proxy(jj);
daili.GiveChocolate();
daili.GiveDolle();
daili.GiveFlowers();
}
}
(完)