C#桥接模式完整实例
2015-07-16 12:05
696 查看
本文实例讲述了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#调用COM组件
- C#实现把指定数据写入串口
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#通用邮件发送类分享
- C#中this的用法集锦
- C#.NET获取拨号连接的宽带连接方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#生成饼形图及添加文字说明实例代码
- C#判等对象是否相等的方法汇总
- C#简单的向量用法实例教程
- C#托管堆对象实例包含内容分析
- C#实现按照指定长度在数字前补0方法小结
- C#虚方法的声明和使用实例教程
- C#获取文件夹及文件的大小与占用空间的方法
- C#定义简单的反射工厂实例分析
- C#数字图象处理之肤色检测的方法