当前位置: 移动技术网 > IT编程>开发语言>c# > C#桥接模式完整实例

C#桥接模式完整实例

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网