Meaningless Drivel is fun!*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Does Bridge design pattern looks like interface in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Does Bridge design pattern looks like interface in Java?" Watch "Does Bridge design pattern looks like interface in Java?" New topic
Author

Does Bridge design pattern looks like interface in Java?

Alexander Yanuar Koentjara
Ranch Hand

Joined: Jun 03, 2002
Posts: 31
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?


===================================<br />Fear not, God know the best.<br />SCJP2 91%<br />SCWCD 89%<br />SCJD2 92% (143/155 pts)<br />SCEA Part I (89%)
Alexander Yanuar Koentjara
Ranch Hand

Joined: Jun 03, 2002
Posts: 31
... or Bridge == interface in java? .. just like template pattern == inheritence in java ..
Atif Shah
Greenhorn

Joined: Jan 30, 2002
Posts: 27
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.
Alberto Dell'Era
Greenhorn

Joined: Mar 02, 2002
Posts: 29
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 ]

Ciao,<br />Alberto
Alexander Yanuar Koentjara
Ranch Hand

Joined: Jun 03, 2002
Posts: 31
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 ]
deneb shah
Ranch Hand

Joined: Feb 13, 2000
Posts: 60
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


denice the menace
Alexander Yanuar Koentjara
Ranch Hand

Joined: Jun 03, 2002
Posts: 31
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

Joined: Mar 02, 2002
Posts: 29
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does Bridge design pattern looks like interface in Java?
 
Similar Threads
Bridge and Facade Pattern
Bridge Design Pattern...
Bridge Design pattern
Adapter Pattern Vs. Bridge Pattern
which design pattern book?