#region The Abstraction
public class Abstraction
{
#region Members
private Bridge _bridge;
#endregion
#region Ctor
/// <summary>
/// Construct a new Abstraction object with
/// the given bridge
/// </summary>
/// <param name="bridge">The given bridge</param>
public Abstraction(Bridge bridge)
{
_bridge = bridge;
}
#endregion
#region Methods
/// <summary>
/// The method demonstrate the call for
/// the bridge object by its abstraction
/// </summary>
public void Operation()
{
Console.Write("Using");
_bridge.OperationImplementation();
}
#endregion
}
#endregion
#region The Bridge And Its Implementations
public interface Bridge
{
void OperationImplementation();
}
public class BridgeImplementationA : Bridge
{
#region Bridge Members
/// <summary>
/// Perform implementation A operation
/// </summary>
public void OperationImplementation()
{
Console.Write("BridgeImplementationA");
}
#endregion
}
public class BridgeImplementationB : Bridge
{
#region Bridge Members
/// <summary>
/// Perform implementation B operation
/// </summary>
public void OperationImplementation()
{
Console.Write("BridgeImplementationB");
}
#endregion
}
#endregion
You can see that the abstraction holds a bridge object and gets the bridge in the
constructor. Therefore, whenever one of the implementation is needed you pass it
in the constructor and you won't be coupled to the implementation.