本文实例讲述了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#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论