c#中代理设计模式,(代码)
答案:2 悬赏:30 手机版
解决时间 2021-04-11 22:46
- 提问者网友:刺鸟
- 2021-04-11 10:39
c#中代理设计模式,(代码)
最佳答案
- 五星知识达人网友:笑迎怀羞
- 2021-04-11 11:54
namespace Delegate
{
interface IGiveGift
{
void GiveDolls();
void GiveFlowers();
void GiveChocolate();
}
class Proxy:IGiveGift
{
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:IGiveGift
{
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; }
}
}
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.ReadKey();
}
}
}
{
interface IGiveGift
{
void GiveDolls();
void GiveFlowers();
void GiveChocolate();
}
class Proxy:IGiveGift
{
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:IGiveGift
{
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; }
}
}
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.ReadKey();
}
}
}
全部回答
- 1楼网友:逃夭
- 2021-04-11 12:10
无代码
再看看别人怎么说的。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯