bridgestructural.cs
来自「使用C#程序将23个常用设计模式进行列表显示」· CS 代码 · 共 81 行
CS
81 行
using System;
using System.Windows.Forms;
using System.Text;
namespace DesignPattern.BridgeStructural
{
class BridgeStructural : AbstractPattern
{
public static void Run(TextBox tbInfo)
{
s_tbInfo = tbInfo;
s_tbInfo.Text = "";
Abstraction ab = new RefinedAbstraction();
// Set implementation and call
ab.Implementor = new ConcreteImplementorA();
ab.Operation();
// Change implemention and call
ab.Implementor = new ConcreteImplementorB();
ab.Operation();
// Wait for user
////Console.Read();
}
}
class Abstraction
{
protected Implementor implementor;
// Property
public Implementor Implementor
{
set
{
implementor = value;
}
}
public virtual void Operation()
{
implementor.Operation();
}
}
// "Implementor"
abstract class Implementor
{
public abstract void Operation();
}
// "RefinedAbstraction"
class RefinedAbstraction : Abstraction
{
public override void Operation()
{
implementor.Operation();
}
}
// "ConcreteImplementorA"
class ConcreteImplementorA : Implementor
{
public override void Operation()
{
DesignPattern.FormMain.OutputInfo("ConcreteImplementorA Operation");
}
}
// "ConcreteImplementorB"
class ConcreteImplementorB : Implementor
{
public override void Operation()
{
DesignPattern.FormMain.OutputInfo("ConcreteImplementorB Operation");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?