新随笔

 1  abstract   class  Mediator
 2  {
 3       public   abstract   void  Register(People people);
 4       public   abstract   void  SetMessage( string  message, People from,  string  to);
 5  }
 6 
 7  class  MatrimonialMediator:Mediator
 8  {
 9       private  List < People >  _list  =   new  List < People > ();
10       public   override   void  Register(People people)
11      {
12          _list.Add(people);
13      }
14       public   override   void  SetMessage( string  message, People from,  string  to)
15      {
16          Console.WriteLine( " {0}通过中介对{1}说:{2} " , from.Name, to, message);
17           foreach  (var item  in  _list)
18          {
19               if  (item.Name  ==  to)
20              {
21                  item.RecevieMessage(message,from.Name);
22                   break ;
23              }
24          }
25      }
26  }
27 
28  abstract   class  People
29  {
30       private    string  _name;
31       private   Mediator _mediator;
32       public  Mediator Mediator
33      {
34           get  {  return  _mediator; }
35      }
36       public   string  Name
37      {
38           get  {  return  _name; }
39      }
40       public  People( string  name, Mediator mediator)
41      {
42          _name  =  name;
43          _mediator  =  mediator;
44          _mediator.Register( this );
45      }
46       public   abstract   void  SetMessage( string  message, string  to);
47       public   abstract   void  RecevieMessage( string  message, string  from);
48  }
49 
50  class  Man:People
51  {
52       public  Man( string  name,Mediator mediator)
53      :  base (name, mediator)
54      {        }
55       public   override   void  SetMessage( string  message, string  to)
56      {
57           this .Mediator.SetMessage(message,  this , to);
58      }
59       public   override   void  RecevieMessage( string  message,  string  from)
60      {
61          Console.WriteLine( string .Format( " {0}(男)收到了{1}的消息:{2} " this .Name, from, message));
62      }
63  }
64 
65  class  Woman:People
66  {
67       public  Woman( string  name, Mediator mediator)
68      :  base (name, mediator)
69      {        }
70       public   override   void  SetMessage( string  message,  string  to)
71      {
72           this .Mediator.SetMessage(message,  this , to);
73      }
74       public   override   void  RecevieMessage( string  message,  string  from)
75      {
76          Console.WriteLine( " {0}(女)收到了{1}的消息:{2} " );
77      }
78  }
79 
80  static   void  Main( string [] args)
81  {
82      MatrimonialMediator matrimonialMediator  =   new  MatrimonialMediator();
83      People HanMeimei  =   new  Woman( " 韩美美 " , matrimonialMediator);
84      People LiLei  =   new  Man( " 李雷 " , matrimonialMediator);
85      HanMeimei.SetMessage( " 约在XXXX见面 " " 李雷 " );
86      Console.Read();
87  }
88 
89 
90 
91 

 

转载于:https://www.cnblogs.com/kevinlocn/archive/2009/12/29/1634630.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值