The bridge pattern
The main difference between adapters and bridges is that adapters are built to correct incompatibilities that arise from our design, whereas a bridge is constructed before, and its purpose is to separate an interface from its implementation, so that we can modify and even replace the implementation without changing client code.
In the following example, we will assume that users of our sandwich builder app will have a choice of open or closed sandwiches. Apart from this one factor, these sandwiches are identical in that they can contain any combination of fillings, although to simplify matters, there will only be a maximum of two ingredients. This will demonstrate how we can decouple an abstract class from its implementations so that they be modified independently.
The following steps explain how to construct a simple bridge pattern:
Begin by creating an interface like the one seen here:
public interface SandwichInterface { void makeSandwich(String filling1...