Decoupling and developing objects independently with the bridge pattern
The goal of this pattern is to separate the abstraction from its implementation so that both can change independently. The bridge pattern was described by the GoF.
Motivation
The bridge pattern is about prioritizing composition over inheritance. The implementation details are moved from the hierarchy to another object with a separate hierarchy. The bridge pattern uses encapsulation and aggregation, and may use inheritance to separate responsibilities into different classes.
Finding it in the JDK
Uses of the bridge pattern can be found in the java.util.logging
package and the implementation of the Logger
class. The class is located in the java.logging
module. It implements the Filter
interface. This interface is used to gain additional control over logged content beyond the standard log level.
Sample code
Let us see an example of two types of vehicles: a sport car and a pickup. The vehicles vary...