宋勇野 通过本文主要向大家介绍了马桶c的个人空间,c语言,欲情 c max,维生素c,奔驰c200等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了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();
}
}
}
</div>
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("运行手机通讯录");
}
}
}
</div>
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();
}
}
}
</div>
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();
}
}
}
</div>
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();
}
}
</div>
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("运行手机游戏");
}
}
}
</div>
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");
}
}
}
</div>
HandSetSoft.cs如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public abstract class HandSetSoft
{
public abstract void Run();
}
}
</div>
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();
}
}
}
</div>
希望本文所述对大家的C#程序设计有所帮助。
</div>
