C#橋接模式完整實(shí)例
本文實(shí)例講述了C#橋接模式實(shí)現(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("運(yùn)行手機(jī)通訊錄");
}
}
}
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("運(yùn)行手機(jī)游戲");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class HandSetMP3:HandSetSoft
{
public override void Run()
{
Console.WriteLine("運(yùn)行手機(jī)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("運(yùn)行手機(jī)通訊錄");
}
}
}
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("運(yùn)行手機(jī)游戲");
}
}
}
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("運(yùn)行手機(jī)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#程序設(shè)計(jì)有所幫助。
相關(guān)文章
基于Unity3D實(shí)現(xiàn)3D迷宮小游戲的示例代碼
迷宮游戲作為經(jīng)典的小游戲,一直深受大家的喜愛。本文小編將為大家詳細(xì)介紹一下如何用Unity實(shí)現(xiàn)一個3D版的迷宮小游戲,感興趣的可以動手試一試2022-03-03
C#實(shí)現(xiàn)數(shù)據(jù)去重的方式總結(jié)
這篇文章主要來和大家一起來討論一下關(guān)于C#數(shù)據(jù)去重的常見的幾種方式,每種方法都有其特點(diǎn)和適用場景,感興趣的小伙伴可以了解一下2023-07-07
Untiy Shader實(shí)現(xiàn)紋理貼圖滾動
這篇文章主要為大家詳細(xì)介紹了Untiy Shader實(shí)現(xiàn)紋理貼圖滾動,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-03-03
C#進(jìn)行PDF表單域的創(chuàng)建填寫與刪除操作
通常情況下,PDF文件是不可編輯的,但PDF表單提供了一些可編輯區(qū)域,允許用戶填寫和提交信息,本文主要介紹了如何使用C#實(shí)現(xiàn)PDF表單域的創(chuàng)建,填寫與刪除操作,感興趣的可以了解下2024-04-04
C# 讀寫自定義的Config文件的實(shí)現(xiàn)方法
本文主要介紹了C# 讀寫自定義的Config文件的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07

