I was questioned by a colleague about the design pattern of my implementation of a WCF windows service in a ASP.net client application and I really could not tell whether it is Bridge or Adapter!
Here is the implementation:
- I have obtained the service contract
- Defined a new interface similar to my WCF Data contract
- I created a WCF client and wrapped it inside the new interface
- Mapped the new interface operations to the original WCF client (I do some logging/error handling here)
I was always thinking of it as an implementation of Adapter pattern, but really I can not tell why isn't it Bridge!
I have read all the posts here in SO, GoF and wikipedia but it really makes no sense!
From my understanding, Both patterns point at an existing type, both decouple an abstraction from its implementation am I missing a point?
Here's from GoF:
The key difference between these patterns lies in their intents. Adapter focuses on resolving incompatibilities between two existing interfaces. It doesn't focus on how those interfaces are implemented, nor does it consider how they might evolve independently. It's a way of making two independently designed classes work together without reimplementing one or the other. Bridge, on the other hand, bridges an abstraction and its (potentially numerous) implementations. It provides a stable interface to clients even as it lets you vary the classes that implement it. It also accommodates new implementations as the system evolves.
I don't fully understand the above statement,
- Does it mean that if I vary the adaptee or change the implementation of the original interface at design time then it is Bridge Pattern?
- The differences sounds trivial, Is there any other differences in implementation/abstcation?
- How can anyone tell what implementation is used after development?
- Can anyone give me a good example of bridge pattern and how it can be changed during software lifecycle?
Update:
Again from GoF:
Remember that an adapter makes two existing interfaces work together as opposed to defining an entirely new one.
Does it mean that changing the existing interface so that it can work with another interface is an implementation of Adapter?
Update2:
Just found this incredible article: Illustrated GOF Design Patterns in C#
This is true Bridge Patter structure:
I was missing the fact that the Bridge pattern lets you combine the different abstractions and implementations and extend them independently