Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,955 | Comments: 44,412

filter by tags archive

Design patterns in the test of timeBridge


The bridge pattern is a design pattern used in software engineering which is meant to "decouple an abstraction from its implementation so that the two can vary independently".The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes.

More about this pattern.

Bridge is quite complex, mostly because it is composed of Abstraction, Refined Abstraction, Implementor and Concrete Implementor. Here is a concrete example (pun intended):

  • Abstraction: CImage
  • Refined Abstraction: CBmpImage, CJpegImage
  • Implementor: CimageImp
  • Concrete Implementor: CWinImp, COS2Imp

In general, I don’t like complex things, and of the top of my head, I can’t think of a time when I used this approach. Until such time when I can see a really good reason why I would want to do something like this, I see very little reason to bother.

Recommendation: Avoid, there are simpler options to solving those sort of problems.

More posts in "Design patterns in the test of time" series:

  1. (21 Jan 2013) Mediator
  2. (18 Jan 2013) Iterator
  3. (17 Jan 2013) Interpreter
  4. (21 Nov 2012) Command, Redux
  5. (19 Nov 2012) Command
  6. (16 Nov 2012) Chain of responsibility
  7. (15 Nov 2012) Proxy
  8. (14 Nov 2012) Flyweight
  9. (09 Nov 2012) Façade
  10. (07 Nov 2012) Decorator
  11. (05 Nov 2012) Composite
  12. (02 Nov 2012) Bridge
  13. (01 Nov 2012) Adapter
  14. (31 Oct 2012) Singleton
  15. (29 Oct 2012) Prototype
  16. (26 Oct 2012) Factory Method
  17. (25 Oct 2012) Builder
  18. (24 Oct 2012) A modern alternative to Abstract Factory–filtered dependencies
  19. (23 Oct 2012) Abstract Factory

Comments

Arnon Rotem-Gal-Oz

You actually see this quite a lot - only what's shown here on the CImage side all have I prefixes (in .NET) i.e. they are all interfaces...

Niv Eliyahu

The bridge pattern come to solve problems that ioc/di solves, the bridge is the oldest way.

Niels Krijger

I've seen this pattern used only used once or twice explicitly; that is, being named "Bridge". However, this pattern -like most others frankly- grow into existence somehow, particularly when you're really set for decoupling two bodies of code.

I regularly have a model project (which I can understand) implemented by a specific technology (which I don't, but with some gOOgling fiddle out in the end). I don't want the difficult technology ruin my simple view of the world (that is, I don't want technology X mess up my model). I think most who are fully dedicated to their models won't let their implementation leak into their model. Henceforth, the Bridge is created; even though the programmer has no idea what is actually is. That is why you hardly ever see it in the real world; it is often decoupled so much you don't even notice.

Kyle Szklenski

As the occasional publisher of APIs, I have used and abused the bridge pattern over and over and over. I've used it more in C++ than in .NET, but it can be useful there, too, at times.

Marek Dec

Your example is somehow wrong. Actually the only Interface here is the one called CImageImp. Why does it have the Imp suffix then? Actually the CImageImp makes me think that it's an implementation of the CImage (which is not obviously not true given the uml notation you used). Then CImage cannot be a pure interface (as somebody suggests here) as it "has" a CImageImp. The quality of the wikipedia article you linked here is much better, I'd say that you read it once again and refine yours.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. What is new in RavenDB 3.5–Intro - 13 hours from now
  2. Production postmortem: The case of the infected cluster - about one day from now

There are posts all the way to Jul 09, 2015

RECENT SERIES

  1. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
  2. Special Offer (2):
    27 May 2015 - 29% discount for all our products
  3. RavenDB Sharding (3):
    22 May 2015 - Adding a new shard to an existing cluster, splitting the shard
  4. Challenge (45):
    28 Apr 2015 - What is the meaning of this change?
  5. Interview question (2):
    30 Mar 2015 - fix the index
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats