首页 / 设计模式 / 大话设计模式-代理模式(7)
大话设计模式-代理模式(7)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了大话设计模式-代理模式(7),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2326字,纯文字阅读大概需要4分钟。
内容图文
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { interface IGiveGift { void GiveDolls(); void GiveFlowers(); void GvieChoolate(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { class Proxy:IGiveGift { Pursuit gg; public Proxy(SchoolGirl mm) { gg = new Pursuit(mm); } publicvoid GiveDolls() { gg.GiveDolls(); } publicvoid GiveFlowers() { gg.GiveFlowers(); } publicvoid GvieChoolate() { gg.GvieChoolate(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { abstract class Subject { public abstract void Request(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { class Pursuit:IGiveGift { SchoolGirl mm; public Pursuit(SchoolGirl mm) { this.mm = mm; } publicvoid GiveDolls() { Console.WriteLine("{0}送你洋娃娃!",mm.Name); } publicvoid GiveFlowers() { Console.WriteLine("{0}送你鲜花!",mm.Name); } publicvoid GvieChoolate() { Console.WriteLine("{0}送你巧克力!",mm.Name); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { class RealSubject:Subject { public override void Request() { Console.WriteLine( " 真实的请求! " ); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { class SubProxy:Subject { RealSubject realSubject; public override void Request() { if (realSubject == null) { realSubject = new RealSubject(); } realSubject.Request(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { class SchoolGirl { private string name; public string Name { get { return name; } set { name = value; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProxyFactory { class Program { static void Main(string[] args) { SchoolGirl mm = new SchoolGirl(); mm.Name = "李娇娇"; Proxy daili = new Proxy(mm); daili.GiveDolls(); daili.GiveFlowers(); daili.GvieChoolate(); SubProxy subProxy = new SubProxy(); subProxy.Request(); Console.ReadLine(); } } }
代理模式
代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问.
原文:http://www.cnblogs.com/rinack/p/5275758.html
内容总结
以上是互联网集市为您收集整理的大话设计模式-代理模式(7)全部内容,希望文章能够帮你解决大话设计模式-代理模式(7)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。