C#桥接模式 C#桥接模式完整实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

C#桥接模式 C#桥接模式完整实例

宋勇野   2021-03-21 我要评论
想了解C#桥接模式完整实例的相关内容吗,宋勇野在本文为您仔细讲解C#桥接模式的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C#,桥接模式,下面大家一起来学习吧。

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

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们