您的位置:首页 > 其它

Mediator 用一个中介者对象来封装一系列的对象交互。中介者使各个对象不需要显式的相互作用,从而使其耦合松散,而且可以独立地改变它们之间的交互。

2007-01-05 17:21 507 查看
using System;
2
3namespace Gof.Test.Mediator
4using System;
2
3namespace Gof.Test.Mediator
4using System;
2
3namespace Gof.Test.Mediator
4using System;
2
3namespace Gof.Test.Mediator
4{
5 public class TubMediator
6 {
7 private System.Collections.Hashtable _tubMachine = new System.Collections.Hashtable();
8 private static TubMediator _mediator;
9 private TubMediator()
10 {}
11 public static TubMediator Singleton()
12 {
13 if(_mediator == null)
14 {
15 _mediator = new TubMediator();
16 }
17 return _mediator;
18 }
19 public Machine GetMachine(Tub t)
20 {
21 return (Machine)_tubMachine[t];
22 }
23 public System.Collections.IList GetTubs(Machine m)
24 {
25 System.Collections.ArrayList al = new System.Collections.ArrayList();
26 System.Collections.IDictionaryEnumerator e = _tubMachine.GetEnumerator();
27 while(e.MoveNext())
28 {
29 if(e.Value.Equals(m))
30 {
31 al.Add(e.Key);
32 }
33 }
34 return al;
35 }
36 public void Set(Tub t,Machine m)
37 {
38 _tubMachine[t] = m;
39 }
40 }
41}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐