The bridge structural pattern allows you to separate an interface from its implementation. Maybe you want to start out doing something one way and then change later. Or maybe you want to share an implementation. Or, if you’re using C++, you can hide how you’re doing something. This is a subtle pattern with a lot of potential.

Maybe you’re creating an application with vehicles in it. This could be a racing game or a driver certification application. You create a base class called Vehicle and derived classes Car, Truck, and Tractor which each inherit from the Vehicle class. Then you need different kinds of engines and since there’s a difference in behavior, you plan to create more classes to specialize. The problem is that not only does this lead to a lot of classes such as GasCar, DieselCar, GasTruck, DieselTruck, and DieselTractor, but you can’t change the type of engine in a car.

Why would you need to do that? Cars always have the same engine, right? Even in real life, vehicles can sometimes change. And this is software. Everything changes in software.

Instead of creating so many derived classes, a better solution will use the bridge pattern to form a link between the basic vehicle types and the engine types. This allows both vehicles and engines to be subclassed or derived from independently of each other. and because this pattern uses composition instead of inheritance, you can easily swap an engine type for another.