欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#橋接模式完整實例

 更新時間:2015年07月16日 12:05:57   作者:宋勇野  
這篇文章主要介紹了C#橋接模式,以實例形式較為詳細的分析了C#橋接模式的實現(xiàn)原理與相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C#橋接模式實現(xiàn)方法。分享給大家供大家參考。具體如下:

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#程序設計有所幫助。

相關文章

  • 基于Unity3D實現(xiàn)3D迷宮小游戲的示例代碼

    基于Unity3D實現(xiàn)3D迷宮小游戲的示例代碼

    迷宮游戲作為經典的小游戲,一直深受大家的喜愛。本文小編將為大家詳細介紹一下如何用Unity實現(xiàn)一個3D版的迷宮小游戲,感興趣的可以動手試一試
    2022-03-03
  • C#實現(xiàn)數據去重的方式總結

    C#實現(xiàn)數據去重的方式總結

    這篇文章主要來和大家一起來討論一下關于C#數據去重的常見的幾種方式,每種方法都有其特點和適用場景,感興趣的小伙伴可以了解一下
    2023-07-07
  • C#關鍵字之重載Overload介紹

    C#關鍵字之重載Overload介紹

    這篇文章介紹了C#關鍵字之重載Overload,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • C#獲取文件創(chuàng)建時間的方法

    C#獲取文件創(chuàng)建時間的方法

    這篇文章主要介紹了C#獲取文件創(chuàng)建時間的方法,涉及C#文件操作的技巧及CreattionTime屬性的使用方法,需要的朋友可以參考下
    2015-04-04
  • C#類中屬性與成員變量的使用小結

    C#類中屬性與成員變量的使用小結

    本篇文章主要是對C#類中屬性與成員變量的使用進行了總結介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • C#幾種獲取網頁源文件代碼的實例

    C#幾種獲取網頁源文件代碼的實例

    C#幾種獲取網頁源文件代碼的實例,需要的朋友可以參考一下
    2013-04-04
  • Untiy Shader實現(xiàn)紋理貼圖滾動

    Untiy Shader實現(xiàn)紋理貼圖滾動

    這篇文章主要為大家詳細介紹了Untiy Shader實現(xiàn)紋理貼圖滾動,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-03-03
  • C#進行PDF表單域的創(chuàng)建填寫與刪除操作

    C#進行PDF表單域的創(chuàng)建填寫與刪除操作

    通常情況下,PDF文件是不可編輯的,但PDF表單提供了一些可編輯區(qū)域,允許用戶填寫和提交信息,本文主要介紹了如何使用C#實現(xiàn)PDF表單域的創(chuàng)建,填寫與刪除操作,感興趣的可以了解下
    2024-04-04
  • c# 防火墻添加/刪除 特定端口的示例

    c# 防火墻添加/刪除 特定端口的示例

    這篇文章主要介紹了c# 如何將特定端口加入防火墻中,幫助大家更好的理解和學習c#,感興趣的朋友可以了解下
    2020-10-10
  • C# 讀寫自定義的Config文件的實現(xiàn)方法

    C# 讀寫自定義的Config文件的實現(xiàn)方法

    本文主要介紹了C# 讀寫自定義的Config文件的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07

最新評論