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

首頁 > 編程 > C# > 正文

C#橋接模式完整實例

2019-10-29 21:40:50
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了C#橋接模式,以實例形式較為詳細的分析了C#橋接模式的實現原理與相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下

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

C#代碼如下:

 

 
  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public class HandAddressList:HandSetSoft 
  7. public override void Run() 
  8. Console.WriteLine("運行手機通訊錄"); 
  9. using System; 
  10. using System.Collections.Generic; 
  11. using System.Linq; 
  12. using System.Text; 
  13. namespace ConsoleApplication1 
  14. public class HandBrandM:HandSetBrand 
  15. public override void Run() 
  16. soft.Run(); 
  17. using System; 
  18. using System.Collections.Generic; 
  19. using System.Linq; 
  20. using System.Text; 
  21. namespace ConsoleApplication1 
  22. public class HandBrandN:HandSetBrand 
  23. public override void Run() 
  24. soft.Run(); 
  25. using System; 
  26. using System.Collections.Generic; 
  27. using System.Linq; 
  28. using System.Text; 
  29. namespace ConsoleApplication1 
  30. public abstract class HandSetBrand 
  31. protected HandSetSoft soft; 
  32. public void SetHandSetSoft(HandSetSoft soft)  
  33. this.soft = soft; 
  34. public abstract void Run(); 
  35. using System; 
  36. using System.Collections.Generic; 
  37. using System.Linq; 
  38. using System.Text; 
  39. namespace ConsoleApplication1 
  40. public class HandSetGame:HandSetSoft 
  41. public override void Run() 
  42. Console.WriteLine("運行手機游戲"); 
  43. using System; 
  44. using System.Collections.Generic; 
  45. using System.Linq; 
  46. using System.Text; 
  47. namespace ConsoleApplication1 
  48. public class HandSetMP3:HandSetSoft 
  49. public override void Run() 
  50. Console.WriteLine("運行手機MP3"); 
  51. using System; 
  52. using System.Collections.Generic; 
  53. using System.Linq; 
  54. using System.Text; 
  55. namespace ConsoleApplication1 
  56. public abstract class HandSetSoft 
  57. public abstract void Run(); 
  58. using System; 
  59. using System.Collections.Generic; 
  60. using System.Linq; 
  61. using System.Text; 
  62. namespace ConsoleApplication1 
  63. class Program 
  64. static void Main(string[] args) 
  65. HandSetBrand ab; 
  66. ab = new HandBrandN(); 
  67. ab.SetHandSetSoft(new HandSetGame()); 
  68. ab.Run(); 
  69. ab.SetHandSetSoft(new HandAddressList()); 
  70. ab.Run(); 
  71. ab = new HandBrandM(); 
  72. ab.SetHandSetSoft(new HandSetGame()); 
  73. ab.Run(); 
  74. ab.SetHandSetSoft(new HandAddressList()); 
  75. ab.Run(); 
  76. ab.SetHandSetSoft(new HandSetMP3()); 
  77. ab.Run(); 
  78. Console.ReadKey(); 

HandAddressList.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public class HandAddressList:HandSetSoft 
  7. public override void Run() 
  8. Console.WriteLine("運行手機通訊錄"); 

HandBrandM.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public class HandBrandM:HandSetBrand 
  7. public override void Run() 
  8. soft.Run(); 

HandBrandN.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public class HandBrandN:HandSetBrand 
  7. public override void Run() 
  8. soft.Run(); 

HandSetBrand.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public abstract class HandSetBrand 
  7. protected HandSetSoft soft; 
  8. public void SetHandSetSoft(HandSetSoft soft)  
  9. this.soft = soft; 
  10. public abstract void Run(); 

HandSetGame.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public class HandSetGame:HandSetSoft 
  7. public override void Run() 
  8. Console.WriteLine("運行手機游戲"); 

HandSetMP3.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public class HandSetMP3:HandSetSoft 
  7. public override void Run() 
  8. Console.WriteLine("運行手機MP3"); 

HandSetSoft.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. public abstract class HandSetSoft 
  7. public abstract void Run(); 

Program.cs如下:

 

 
  1. ?using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. namespace ConsoleApplication1 
  6. class Program 
  7. static void Main(string[] args) 
  8. HandSetBrand ab; 
  9. ab = new HandBrandN(); 
  10. ab.SetHandSetSoft(new HandSetGame()); 
  11. ab.Run(); 
  12. ab.SetHandSetSoft(new HandAddressList()); 
  13. ab.Run(); 
  14. ab = new HandBrandM(); 
  15. ab.SetHandSetSoft(new HandSetGame()); 
  16. ab.Run(); 
  17. ab.SetHandSetSoft(new HandAddressList()); 
  18. ab.Run(); 
  19. ab.SetHandSetSoft(new HandSetMP3()); 
  20. ab.Run(); 
  21. Console.ReadKey(); 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和静县| 南岸区| 太和县| 赤水市| 萨迦县| 茂名市| 满城县| 乐都县| 阳城县| 天台县| 清流县| 柘荣县| 阿拉善盟| 青铜峡市| 特克斯县| 东宁县| 德兴市| 河津市| 来宾市| 肃南| 原平市| 开鲁县| 昂仁县| 蕲春县| 巴里| 襄樊市| 长武县| 巴林左旗| 义乌市| 台安县| 都安| 昌吉市| 绥宁县| 海阳市| 绩溪县| 麟游县| 汉沽区| 陵水| 安岳县| 清丰县| 中江县|