手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#桥接模式完整实例
C#桥接模式完整实例
摘要:本文实例讲述了C#桥接模式实现方法。分享给大家供大家参考。具体如下:C#代码如下:usingSystem;usingSystem.Colle...

本文实例讲述了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#程序设计有所帮助。

【C#桥接模式完整实例】相关文章:

C# 拓展方法的简单实例

c#实现sunday算法实例

C#日期转换函数分享

c#文件的复制,移动,创建(实例代码)

C#生成注册码的实例代码

c#典型工厂化实现实例

c#(Socket)异步套接字代码示例

基于c# 接口的实例详解

C#连接Oracle数据库的实例方法

C# 对XML操作入门实例

精品推荐
分类导航