近日以來,亞太問題引起了世界的關注,習主席將亞太問題歸結爲熱點敏感問題、民族宗教矛盾恐怖主義、跨國犯罪、環境安全、網絡安全、能源資源安全、重大自然災害,同時由於各國利益衝突的存在,使得亞太問題持續升溫。爲了響應和平發展的口號,順應時代發展的驅使,各國代表在菲律賓召開了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>
運行的結果如下:
當然,這個例子也許並不是很適用於模式,但是最近亞太局勢如此緊張,也讓自己不得不去關注一下。在此聲明,此篇文章沒有任何極端情感存在,只是作爲自己學習只是和國家時事的一個小小結合,還請大家多多指正,很希望得到大家的意見和建議!