程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#設計模式之橋梁設計模式(Bridge)(2)

C#設計模式之橋梁設計模式(Bridge)(2)

編輯:關於C語言
、橋梁模式的示意性源代碼

// Bridge pattern -- Structural example 
using System;
// "Abstraction"
class Abstraction
{
 // FIElds
 protected Implementor implementor;
 // PropertIEs
 public Implementor Implementor
 {
  set{ implementor = value; }
 }
 // Methods
 virtual public void Operation()
 {
  implementor.Operation();
 }
}
// "Implementor"
abstract class Implementor
{
 // Methods
 abstract public void Operation();
}
// "RefinedAbstraction"
class RefinedAbstraction : Abstraction
{
 // Methods
 override public void Operation()
 {
  implementor.Operation();
 }
}
// "ConcreteImplementorA"
class ConcreteImplementorA : Implementor
{
 // Methods
 override public void Operation()
 {
  Console.WriteLine("ConcreteImplementorA Operation");
 }
}
// "ConcreteImplementorB"
class ConcreteImplementorB : Implementor
{
 // Methods
 override public void Operation()
 {
  Console.WriteLine("ConcreteImplementorB Operation");
 }
}
/**//// <summary>
/// ClIEnt test
/// </summary>
public class ClIEnt
{
 public static void Main( string[] args )
 {
  Abstraction abstraction = new RefinedAbstraction();
  // Set implementation and call
  abstraction.Implementor = new ConcreteImplementorA();
  abstraction.Operation();
  // Change implemention and call
  abstraction.Implementor = new ConcreteImplementorB();
  abstraction.Operation();
 }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved