国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#橋接模式完整實例

2020-01-24 01:37:05
字體:
來源:轉載
供稿:網友

本文實例講述了C#橋接模式實現方法。分享給大家供大家參考。具體如下:

C#代碼如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandAddressList:HandSetSoft  {    public override void Run()    {      Console.WriteLine("運行手機通訊錄");    }  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandBrandM:HandSetBrand  {    public override void Run()    {      soft.Run();    }  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandBrandN:HandSetBrand  {    public override void Run()    {      soft.Run();    }  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public abstract class HandSetBrand  {    protected HandSetSoft soft;    public void SetHandSetSoft(HandSetSoft soft)     {      this.soft = soft;    }    public abstract void Run();  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandSetGame:HandSetSoft  {    public override void Run()    {      Console.WriteLine("運行手機游戲");    }  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandSetMP3:HandSetSoft  {    public override void Run()    {      Console.WriteLine("運行手機MP3");    }  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public abstract class HandSetSoft  {    public abstract void Run();  }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  class Program  {    static void Main(string[] args)    {      HandSetBrand ab;      ab = new HandBrandN();      ab.SetHandSetSoft(new HandSetGame());      ab.Run();      ab.SetHandSetSoft(new HandAddressList());      ab.Run();      ab = new HandBrandM();      ab.SetHandSetSoft(new HandSetGame());      ab.Run();      ab.SetHandSetSoft(new HandAddressList());      ab.Run();      ab.SetHandSetSoft(new HandSetMP3());      ab.Run();      Console.ReadKey();    }  }}

HandAddressList.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandAddressList:HandSetSoft  {    public override void Run()    {      Console.WriteLine("運行手機通訊錄");    }  }}

HandBrandM.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandBrandM:HandSetBrand  {    public override void Run()    {      soft.Run();    }  }}

HandBrandN.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandBrandN:HandSetBrand  {    public override void Run()    {      soft.Run();    }  }}

HandSetBrand.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public abstract class HandSetBrand  {    protected HandSetSoft soft;    public void SetHandSetSoft(HandSetSoft soft)     {      this.soft = soft;    }    public abstract void Run();  }}

HandSetGame.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandSetGame:HandSetSoft  {    public override void Run()    {      Console.WriteLine("運行手機游戲");    }  }}

HandSetMP3.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  public class HandSetMP3:HandSetSoft  {    public override void Run()    {      Console.WriteLine("運行手機MP3");    }  }}

HandSetSoft.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ public abstract class HandSetSoft  {    public abstract void Run();  }}

Program.cs如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{  class Program  {    static void Main(string[] args)    {      HandSetBrand ab;      ab = new HandBrandN();      ab.SetHandSetSoft(new HandSetGame());      ab.Run();      ab.SetHandSetSoft(new HandAddressList());      ab.Run();      ab = new HandBrandM();      ab.SetHandSetSoft(new HandSetGame());      ab.Run();      ab.SetHandSetSoft(new HandAddressList());      ab.Run();      ab.SetHandSetSoft(new HandSetMP3());      ab.Run();      Console.ReadKey();    }  }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 甘德县| 洛宁县| 若羌县| 杭州市| 千阳县| 来凤县| 育儿| 新巴尔虎左旗| 宁都县| 衡东县| 万全县| 巴林左旗| 积石山| 内乡县| 普兰县| 德清县| 永兴县| 鱼台县| 双桥区| 高要市| 南开区| 鸡东县| 海南省| 长岛县| 河曲县| 大足县| 临颍县| 泰宁县| 丰城市| 陆川县| 二连浩特市| 瑞丽市| 沛县| 民权县| 盱眙县| 兴安盟| 大安市| 西昌市| 临漳县| 阿坝| 凯里市|