Bridge Pattern

The Bridge design pattern is a structural design pattern, which decouples an abstraction from its implementation so that the two can vary independently. This pattern involves an interface acting as a bridge that makes the functionality of concrete classes independent from interface implementer classes. Both types of classes can be altered structurally without affecting each other.

The pattern includes the following components:

  1. Abstraction: This is an interface or abstract class that defines the methods that the Client will use. The Abstraction maintains a reference to an object of type Implementor.

  2. RefinedAbstraction: These are classes that extend or implement the Abstraction. These classes are the ones the Client uses to call the methods it needs.

  3. Implementor: This is an interface or abstract class that defines the methods the Abstraction needs. This interface is implemented by the concrete implementation classes.

  4. ConcreteImplementor: These are the classes that implement the Implementor interface. The methods in these classes are called by the methods in the classes that implement or extend the Abstraction.