C#桥接模式完整实例
本文实例讲述了C#桥接模式实现方法。分享给大家供大家参考。具体如下:
C#代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandAddressList:HandSetSoft
{
publicoverridevoidRun()
{
Console.WriteLine("运行手机通讯录");
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandBrandM:HandSetBrand
{
publicoverridevoidRun()
{
soft.Run();
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandBrandN:HandSetBrand
{
publicoverridevoidRun()
{
soft.Run();
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicabstractclassHandSetBrand
{
protectedHandSetSoftsoft;
publicvoidSetHandSetSoft(HandSetSoftsoft)
{
this.soft=soft;
}
publicabstractvoidRun();
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandSetGame:HandSetSoft
{
publicoverridevoidRun()
{
Console.WriteLine("运行手机游戏");
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandSetMP3:HandSetSoft
{
publicoverridevoidRun()
{
Console.WriteLine("运行手机MP3");
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicabstractclassHandSetSoft
{
publicabstractvoidRun();
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
classProgram
{
staticvoidMain(string[]args)
{
HandSetBrandab;
ab=newHandBrandN();
ab.SetHandSetSoft(newHandSetGame());
ab.Run();
ab.SetHandSetSoft(newHandAddressList());
ab.Run();
ab=newHandBrandM();
ab.SetHandSetSoft(newHandSetGame());
ab.Run();
ab.SetHandSetSoft(newHandAddressList());
ab.Run();
ab.SetHandSetSoft(newHandSetMP3());
ab.Run();
Console.ReadKey();
}
}
}
HandAddressList.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandAddressList:HandSetSoft
{
publicoverridevoidRun()
{
Console.WriteLine("运行手机通讯录");
}
}
}
HandBrandM.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandBrandM:HandSetBrand
{
publicoverridevoidRun()
{
soft.Run();
}
}
}
HandBrandN.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandBrandN:HandSetBrand
{
publicoverridevoidRun()
{
soft.Run();
}
}
}
HandSetBrand.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicabstractclassHandSetBrand
{
protectedHandSetSoftsoft;
publicvoidSetHandSetSoft(HandSetSoftsoft)
{
this.soft=soft;
}
publicabstractvoidRun();
}
}
HandSetGame.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandSetGame:HandSetSoft
{
publicoverridevoidRun()
{
Console.WriteLine("运行手机游戏");
}
}
}
HandSetMP3.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicclassHandSetMP3:HandSetSoft
{
publicoverridevoidRun()
{
Console.WriteLine("运行手机MP3");
}
}
}
HandSetSoft.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
publicabstractclassHandSetSoft
{
publicabstractvoidRun();
}
}
Program.cs如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplication1
{
classProgram
{
staticvoidMain(string[]args)
{
HandSetBrandab;
ab=newHandBrandN();
ab.SetHandSetSoft(newHandSetGame());
ab.Run();
ab.SetHandSetSoft(newHandAddressList());
ab.Run();
ab=newHandBrandM();
ab.SetHandSetSoft(newHandSetGame());
ab.Run();
ab.SetHandSetSoft(newHandAddressList());
ab.Run();
ab.SetHandSetSoft(newHandSetMP3());
ab.Run();
Console.ReadKey();
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
热门推荐
10 给儿子新婚祝福语简短
11 新郎朋友祝福语简短大气
12 幼儿祝福语大全简短贺卡
13 中秋祝福语简短女朋友
14 同事生日祝福语简短独特
15 赛前祝福语加姓名简短
16 高考成绩高分祝福语简短
17 谢谢学校老师祝福语简短
18 新婚贺词祝福语创意简短