Bridge Pattern
Role
The Bridge pattern decouples an abstraction from its implementation, enabling them to vary independently. The Bridge pattern is useful when a new version of software is brought out that will replace an existing version, but the older version must still run for its existing client base. The client code will not have to change, as it is conforming to a given abstraction, but the client will need to indicate which version it wants to use.
Illustration
Consider the rolling out of a new version of the .NET Framework used to compile and run C# 3.0. You can have several versions of the Framework loaded on your computer at any time and can select which one to use by externally setting a path to it in the Windows operating system. Setting the path is the bridge between what applications want from the Framework and the actual version they will get. In Figure 2-6, you can see that there are five versions of the Framework loaded on my computer. Figure 2-7 shows that the one the system is being directed to is Version 3.5, which includes the C# 3.0 compiler.
![Bridge pattern illustration (a)—environment Path variable set to Version 3.5](/api/v2/epubs/9780596527730/files/httpatomoreillycomsourceoreillyimages8835.png)
Figure 2-6. Bridge pattern illustration (a)—environment Path variable set to Version 3.5
![Bridge pattern illustration (b)—five versions of the .NET Framework loaded](/api/v2/epubs/9780596527730/files/httpatomoreillycomsourceoreillyimages8837.png)
Figure 2-7. Bridge pattern illustration (b)—five versions of the .NET Framework loaded
Design
Inheritance is a common way to specify different ...
Get C# 3.0 Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.