Skip to content

Instantly share code, notes, and snippets.

@nickyeh97
Created December 20, 2018 10:28
Show Gist options
  • Save nickyeh97/f274f8e51b812889b0bd2f6f24900ed3 to your computer and use it in GitHub Desktop.
Save nickyeh97/f274f8e51b812889b0bd2f6f24900ed3 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
namespace DesignPattern_Bridge
{
// 定義作類別之共用介面
public abstract class Implementor
{
public abstract void OperationImp();
}
// 實作Implementor所訂之介面
public class ConcreteImplementor1 : Implementor
{
public ConcreteImplementor1(){}
public override void OperationImp()
{
Debug.Log("執行Concrete1Implementor.OperationImp");
}
}
// 實作Implementor所訂之介面
public class ConcreteImplementor2 : Implementor
{
public ConcreteImplementor2(){}
public override void OperationImp()
{
Debug.Log("執行Concrete2Implementor.OperationImp");
}
}
// 抽象體的介面,維護指向Implementor的物件 reference
public abstract class Abstraction
{
private Implementor m_Imp = null;
public void SetImplementor( Implementor Imp )
{
m_Imp = Imp;
}
public virtual void Operation()
{
if( m_Imp!=null)
m_Imp.OperationImp();
}
}
// 擴充Abstraction所訂之介面
public class RefinedAbstraction1 : Abstraction
{
public RefinedAbstraction1(){}
public override void Operation()
{
Debug.Log("物件RefinedAbstraction1");
base.Operation();
}
}
// 擴充Abstraction所訂之介面
public class RefinedAbstraction2 : Abstraction
{
public RefinedAbstraction2(){}
public override void Operation()
{
Debug.Log("物件RefinedAbstraction2");
base.Operation();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment