找传奇、传世资源到传世资源站!

C# 设计模式之【代理模式】

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C# 设计模式之【代理模式】 C#语言基础-第1张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; } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复