桥接模式基本实现:
public abstract class Implementor
{
public abstract void OperationImp();
}
public class ConcreteImplementorA : Implementor
{
public override void OperationImp()
{
Console.WriteLine("具体实现A的方法");
}
}
public class ConcreteImplementorB : Implementor
{
public override void OperationImp()
{
Console.WriteLine("具体实现B的方法");
}
}
public class Abstracttion
{
public virtual void Operation()
{
}
}
public class RefinedAbstraction : Abstracttion
{
private Implementor myImplementor;
public RefinedAbstraction(Implementor implementor)
{
myImplementor = implementor;
}
public override void Operation()
{
myImplementor.OperationImp();
}
}
客户端调用:
static void Main(string[] args)
{
Abstracttion A = new RefinedAbstraction(new ConcreteImplementorA());
Abstracttion B = new RefinedAbstraction(new ConcreteImplementorB());
A.Operation();
B.Operation();
Console.ReadKey();
}