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 妈妈生日祝福语简短励志