Design Pattern : Adapter Versus Bridge

Connect with

Adapter vs Bridge Design PatternsLearn Adapter vs Bridge design patterns, structurally both are the same with different intent. Let me explain the similarity and differences between them.

1. Overview of Adapter vs Bridge

These two design pattern, i.e. Adapter and Bridge looks similar somewhere but intent of both are different. Here, first letter of both describe about their pattern. Well, be logical and you can link logically/illogically to remember things most of the time , specially if you want to learn for longer period of time :). In Bridge pattern , first letter is ‘B’ means Before design, this pattern which considerable at design time. In Adapter first letter is A means After , it means after design it can be considered. These B and A letter is used here just to keep in mind or you can say learning purpose. Let me explain the similarity and differences between them.

2. Bridge Design Pattern

Decouple an abstraction from its implementation so that the two can vary independently.

3. Adapter Design Pattern

Make 2 different interfaces compatible

The adapter changes the Interface, which means to make the 2 different interfaces compatible.

where Adapter design pattern used?

Let me take an example of client code which is your application code and third-party library code. If you have to make 2 different interfaces retrofitted between them for two different reasons.

  1. first, you don’t want to change your client code , due to fragility nature of code or extensible nature of code which is already in production.
  2. Second, you don’t have access of third party library which you can not change.

Then, you need to implement class which, implements client interface and compose Adaptee in a class which in-turns make compatible between client and Adaptee.

4. Key Points of Adapter vs Bridge design patterns

  • Adapter and Bridge both used to solve different design issue.
  • Adapter and Bridge both work under concealing the details.
  • Adapter pattern is more of a after design time while Bridge pattern is more of a design time pattern.

5. References

I hope you enjoyed this post of Adapter vs Bridge design pattern, and you can visit design patterns tutorial for more details


Connect with

Leave a Comment

Your email address will not be published. Required fields are marked *