Bridge
Context: Decouple an abstraction from its implementation so that the two can vary independently.
public interface IImplementation{ void OperationImpl();}
public class ConcreteImplA : IImplementation{ public void OperationImpl() => Console.WriteLine("Impl A");}
public abstract class Abstraction{ protected IImplementation _impl; protected Abstraction(IImplementation impl) => _impl = impl; public abstract void Operation();}
public class RefinedAbstraction : Abstraction{ public RefinedAbstraction(IImplementation impl) : base(impl) { } public override void Operation() => _impl.OperationImpl();}Real-world usage example
Section titled “Real-world usage example”Device drivers and remote controls: A remote control abstraction can work with different device implementations (TV, radio, projector). Adding a new remote (e.g., voice remote) doesn’t affect device classes.
Example: In .NET, Stream is an abstraction; FileStream, MemoryStream are implementations. GZipStream is another abstraction that uses a stream implementation – bridge pattern.