C#设计模式扩展——Meditor+Proxy模式实现
2016-12-05 11:10
567 查看
这里我们做一个简单的设计模式的组合,中介者模式+代理模式。代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { public class Agent:AbstractNeeder { public Agent(AbstractMeditor meditor) : base(meditor) { } private Needer need; public Needer Need { get { return need; } set { need = value; } } public void Sending(string message) { meditor.Send(message,need); } public void Notify(string message) { Console.WriteLine("待业者收到信息:" + message); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { public class Meditor:AbstractMeditor { private employeer employeering; public employeer Employeering { get { return employeering; } set { employeering = value; } } private Agent agent; public Agent Agent { get { return agent; } set { agent = value; } } public override void Send(string Message, AbstractNeeder employeer) { if (employeer == employeering) { employeering.Sending(Message); } else { agent.Sending(Message); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { public class Needer:AbstractNeeder { public Needer(AbstractMeditor meditor) : base(meditor) { } public void Sending(string message) { meditor.Send(message,this); } public void Notify(string message ) { Console.WriteLine("待业者收到信息:"+message); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { public class employeer:AbstractNeeder { public employeer(AbstractMeditor meditor) : base(meditor) { } public void Sending(string message) { meditor.Send(message,this ); } public void Notify(string message ) { Console.WriteLine("企业收到信息:"+message); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { public abstract class AbstractNeeder { protected AbstractMeditor meditor; public AbstractNeeder(AbstractMeditor meditor) { this.meditor = meditor; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { public abstract class AbstractMeditor { public abstract void Send(string Message, AbstractNeeder employeer); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProxyAndMeditor0922 { class Program { static void Main(string[] args) { Meditor md = new Meditor(); Needer nd = new Needer(md); employeer ep = new employeer(md); Agent ag = new Agent(md); ag.Notify("我需要一个熟练使用unity3D的开发!"); ep.Notify("我有Unity3D的开发经验,我想找一份与之相关 a1cf 的工作!"); Console.ReadKey(); } } }
相关文章推荐
- 与王翔面对面——《设计模式——基于C#的工程化实现及扩展》作者访谈录
- 【出版直播】博客园征途系列,《设计模式——基于C#的工程化实现及扩展》今天上市,共飨博客园圣诞大餐
- 《模式——工程化实现及扩展》(设计模式C# 版)《状态模式 State》——“自我检验" 参考答案
- 《模式——工程化实现及扩展》(设计模式C# 版)《工厂方法模式 Factory Method》——“自我检验" 参考答案
- 《模式——工程化实现及扩展》(设计模式C# 版)《迭代器模式 Iterator》——“自我检验" 参考答案
- 【出版直播】博客园征途系列,《设计模式--基于C#的工程化实现及扩展》专题上线
- [每周特惠]WPF编程(第二版) + 设计模式—基于C#的工程化实现及扩展
- 《模式——工程化实现及扩展》(设计模式C# 版)《创建者模式 Builder》——正文完整示例
- 《模式——工程化实现及扩展》(设计模式C# 版)《中介者模式 Mediator》——“自我检验" 参考答案
- 设计模式--基于C#的工厂化实现及扩展
- 【出版直播】博客园征途系列,《设计模式——基于C#的工程化实现及扩展》定价修改
- 《设计模式--基于C#的工程化实现及扩展》 Security Design Pattern 系列 3 检查点模式(Check Point)
- .NET平台自带的AOP机制 转自《设计模式--基于c#的工程化实现及扩展》
- 《模式——工程化实现及扩展》(设计模式C# 版)《重新研读C#语言》——“自我检验" 参考答案:依赖注入部分
- 《设计模式--基于C#的工程化实现及扩展》 Security Design Pattern 系列 1 公钥体系与分布式环境要求
- 【出版直播】博客园征途系列,《设计模式——基于C#的工程化实现与扩展》电子书、示例代码发布,互动网预订开始
- 《设计模式——基于C#的工程化实现及扩展》示例说明
- [每周特惠] 设计模式——基于C#的工程化实现及扩展+博客园2010T恤
- 《模式——工程化实现及扩展》(设计模式C# 版)《备忘录模式 Memento》——“自我检验"
- 设计模式-基于C#的工程化实现及扩展 (目录)