近日以来,亚太问题引起了世界的关注,习主席将亚太问题归结为热点敏感问题、民族宗教矛盾恐怖主义、跨国犯罪、环境安全、网络安全、能源资源安全、重大自然灾害,同时由于各国利益冲突的存在,使得亚太问题持续升温。为了响应和平发展的口号,顺应时代发展的驱使,各国代表在菲律宾召开了20104香格里拉对话,在此次对话上也让我们看到了部分国家的言行不一、搬弄是非、扩大不稳定因素等行为,让诸多代表发指。
恰巧自己刚学习了中介者模式,感觉对于这种关系很适用该模式,所以自己认真研究了一番,以下是自己代码
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _25中介者模式
{
class Program
{
//沟通平台
abstract class CommunicationPlatform
{
public abstract void Declare(string message, Country colleague);
}
//国家
abstract class Country
{
protected CommunicationPlatform platform;
public Country(CommunicationPlatform platform)
{
this.platform = platform ;
}
}
//美国类
class USA : Country
{
public USA(CommunicationPlatform platform)
: base(platform )
{ }
public void Delare(string message)
{
platform.Declare(message, this);
}
public void GetMessage(string message)
{
Console.WriteLine("美国获得对方信息:" + message);
}
}
//中国类
class China : Country
{
public China(CommunicationPlatform platform)
: base(platform )
{ }
public void Declare(string message)
{
platform.Declare(message, this);
}
public void GetMessage(string message)
{
Console.WriteLine("中国获得对方信息:" + message);
}
}
//香格里拉对话(具体平台)
class UnitedNntionsSecurityCouncil : CommunicationPlatform
{
private USA colleague1;
private China colleague2;
//美国
public USA Colleague1
{
set { colleague1 = value; }
}
//中国
public China Colleague2
{
set { colleague2 = value; }
}
//声明
public override void Declare(string message, Country colleague)
{
if(colleague==colleague1 )
{
colleague2.GetMessage(message );
}
else
{
colleague1.GetMessage(message );
}
}
}
static void Main(string[] args)
{
UnitedNntionsSecurityCouncil UNSC = new UnitedNntionsSecurityCouncil();
USA c1 = new USA(UNSC);
China c2 = new China (UNSC);
UNSC.Colleague1 = c1;
UNSC.Colleague2 = c2;
c1.Delare("我要做老大,谁也不能撼动我的权利!");
c2.Declare("我们不争做什么“老大”,我们只会为了自己的发展而维护自己的利益!");
Console.Read();
}
}
}
</strong></span>
当然,这个例子也许并不是很适用于模式,但是最近亚太局势如此紧张,也让自己不得不去关注一下。在此声明,此篇文章没有任何极端情感存在,只是作为自己学习只是和国家时事的一个小小结合,还请大家多多指正,很希望得到大家的意见和建议!
香格里拉对话——中介者模式有想法,布布扣,bubuko.com
原文地址:http://blog.csdn.net/u010508826/article/details/27981767