static void Main(string[] args) { Console.WriteLine("欢迎来到.net高级班公开课之设计模式特训课,今天是Eleven为大家带来的桥接模式"); Console.WriteLine("******************************"); { BasePhone phone = new iPhone(); phone.Call(); phone.Text(); } Console.WriteLine("******************************"); { BasePhone phone = new Galaxy(); phone.Call(); phone.Text(); } Console.WriteLine("******************************"); { BasePhone phone = new iPhoneAndroid(); phone.Call(); phone.Text(); } Console.WriteLine("******************************"); { BasePhone phone = new GalaxyIOS(); phone.Call(); phone.Text(); } ISystem android = new AndroidSystem(); ISystem ios = new IOSSystem(); ISystem winphone = new WinphoneSystem(); Console.WriteLine("******************************"); { BasePhoneBridge phone = new GalaxyBridge(); phone.SystemVersion = android; phone.Call(); phone.Text(); } { BasePhoneBridge phone = new GalaxyBridge(); phone.SystemVersion = ios; phone.Call(); phone.Text(); } { BasePhoneBridge phone = new GalaxyBridge(); phone.SystemVersion = winphone; phone.Call(); phone.Text(); } Console.Read(); }
/// <summary> /// 桥接模式【变化封装】 /// 那里变化就封装那里 /// 解决多维度的变化 /// 缺点 :把变化的逻辑交给了上方。上端需要知道更多的细节 /// </summary> /// <returns></returns> // GET: BridePattern public ActionResult Index() { Isystem Android = new AndroidSystem(); Iversion AndroidVersion = new AndroidSystem(); Isystem Winform = new WindfromSystem(); Iversion WinfomVersion = new WindfromSystem(); BasePhoneBridge phone = new GalaxyBridge(); phone.System = Android; phone.Version = AndroidVersion; phone.Call(); phone.Text(); BasePhoneBridge lumaxi = new lumiaBridge(); lumaxi.System = Winform; lumaxi.Version = WinfomVersion; return(View()); }
public void Show() { #region 没用桥接模式前的代码 //{ // BasePhone phone = new iPhone(); // phone.Call(); // phone.Text(); // Console.WriteLine("********************"); //} //{ // BasePhone phone = new Galaxy(); // phone.Call(); // phone.Text(); // Console.WriteLine("********************"); //} //{ // BasePhone phone = new GalaxyIOS(); // phone.Call(); // phone.Text(); // Console.WriteLine("********************"); //} //{ // BasePhone phone = new iPhoneAndroid(); // phone.Call(); // phone.Text(); // Console.WriteLine("********************"); //} #endregion ///一下是用桥接模式优化的代码 ISystem android = new AndroidSystem(); ISystem IOS = new IOSSystem(); ISystem WinPhone = new WinPhoneSystem(); Console.WriteLine("********************"); { BasePhoneBridge phone = new iPhoneBridge(); phone.SystemVersion = IOS; phone.Call(); phone.Text(); } Console.WriteLine("********************"); { BasePhoneBridge phone = new GalaxyBridge(); phone.SystemVersion = android; phone.Call(); phone.Text(); } Console.WriteLine("********************"); { BasePhoneBridge phone = new WinPhoneBridge(); phone.SystemVersion = WinPhone; phone.Call(); phone.Text(); } Console.WriteLine("********************"); { BasePhoneBridge phone = new iPhoneBridge(); phone.SystemVersion = android; phone.Call(); phone.Text(); } }