• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does Bridge design pattern looks like interface in Java?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From design pattern book, I found that Bridge's goal is to separate the interface of class with its implementations (which may do different business logic).
The question is: what is the different between Bridge and interface in java?
 
Alexander Yanuar Koentjara
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... or Bridge == interface in java? .. just like template pattern == inheritence in java ..
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well as the patterns say it sperates the Interfaces from the Implementation.
AS per my understanding you can take it like JDBC-ODBC implementation(i think so :|) ). which provides high level interfaces to call and execute quries without exposing the implementation details.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alexander Yanuar Koentjara:
From design pattern book, I found that Bridge's goal is to separate the interface of class with its implementations (which may do different business logic).
The question is: what is the different between Bridge and interface in java?


By "Interface" they don't mean the Java interface, since DPs are language-agnostic and they don't care if you use Java, C++, Eiffel ...
Being confused is totally appropriate, since this is one of the most difficult patterns to grasp (but also the most useful).
In the Bridge DP they don't use the term "Interface " but "Abstraction" instead:
"The Bridge Pattern separates the Abstraction from the Implementation ..."
The Abstraction of Bridge is actually a hierarchy of classes (not a single class) and the Implementation is another hierarchy of classes; the two are connected through a reference from the root class of Interface to the root class of Implementation. When you draw it on paper it resembles a bridge (hence the name, even if other interpretation is possible, of course).
(Please note that this is just one of a number of possible "prototypycal" arrangement of classes).
There's a wonderful dissertation about the Bridge DP on "Design Patterns Explained" by Alan Shalloway, a wonderful book, not only on DP but on OOA/OOP in general.
[ June 05, 2002: Message edited by: Alberto Dell'Era ]
 
Alexander Yanuar Koentjara
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alberto Dell'Era:

By "Interface" they don't mean the Java interface, since DPs are language-agnostic and they don't care if you use Java, C++, Eiffel ...


Hmm... I just stated the equality of interface (in java) and Bridge. And, I'm still thinking that the design pattern used in "java language's interface" is Bridge..


In the Bridge DP they don't use the term "Interface " but "Abstraction" instead:
"The Bridge Pattern separates the Abstraction from the Implementation ..."


Yup, you're taking from different book.. I got the references in PDF file: Design Pattern (Java Companion) by James W. Cooper. He uses the term "interface" instead. Now, if the abstract class or base class is used for inheritence, doesn't that sound like Prototype design pattern?


The Abstraction of Bridge is actually a hierarchy of classes (not a single class) and the Implementation is another hierarchy of classes; the two are connected through a reference from the root class of Interface to the root class of Implementation. When you draw it on paper it resembles a bridge (hence the name, even if other interpretation is possible, of course).
(Please note that this is just one of a number of possible "prototypycal" arrangement of classes).


Correct me if I am wrong, in JDBC the root interface is the Driver and the hierarcy you mentioned are Resultset, Connection, Statement, etc. Now I get a clearer picture. Thanks very much!
But then, if there is currently only one possible implementations for the root interface and the hierarchy, that become a Facade design pattern!! cool!


There's a wonderful dissertation about the Bridge DP on "Design Patterns Explained" by Alan Shalloway, a wonderful book, not only on DP but on OOA/OOP in general.


Thanks for pointing it out. I will try to find this book in bookstore.
[ June 05, 2002: Message edited by: Alexander Yanuar Koentjara ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the usability of the object guides what pattern is it and not just the mere appreances...
You will be an architect soon... be rationale
 
Alexander Yanuar Koentjara
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by deneb shah:
I guess the usability of the object guides what pattern is it and not just the mere appreances...
You will be an architect soon... be rationale


Yup true.. but this kind of question appears on the Exam part I. Practical and theoritical is two separate world ..
 
Alberto Dell'Era
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alexander Yanuar Koentjara:
Hmm... I just stated the equality of interface (in java) and Bridge. And, I'm still thinking that the design pattern used in "java language's interface" is Bridge..


The Java Interface can be used in almost any pattern, e.g. as the return type of a factory method, as the Adapter supertype of the Adapter DP ... as I said previously, there's no relation between the Java Interface and the word "Interface" in DP terminology.
You may *use* a java interface as en *element* of DP realization in Java, but perhaps you can use an abstract class instead, or a non-abstract class.
There are a lot of different resources that explain what the concept of a DP is. My favourite is the "Design Patterns Explained" book I quoted above.


Yup, you're taking from different book.. I got the references in PDF file: Design Pattern (Java Companion) by James W. Cooper. He uses the term "interface" instead


I was quoting from the Gang Of Four book, which is the "father of all books about DPs", and from "Design Patterns Explained". ;-)
I own the book you mention, but it's one of the few books I dislike (I'm not the only one, see the reviews on Amazon).


Correct me if I am wrong, in JDBC the root interface is the Driver and the hierarcy you mentioned are Resultset, Connection, Statement, etc. Now I get a clearer picture. Thanks very much!
But then, if there is currently only one possible implementations for the root interface and the hierarchy, that become a Facade design pattern!!



:roll: Ehm ... no. The hierarchies in Bridge are both "is-a" hierarchies, and definitely a Statement is NOT a Connection (you may say that a Connection has-a statement instead). And, amazingly, confusing the Bridge and the Facade pattern is a so-common mistake that is reported in the Design Patterns Explained book! Of course that's because the Authors are both OOP instructors ...
Of course, I get a dollar for every DPE copy sold
[ June 06, 2002: Message edited by: Alberto Dell'Era ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic