I found from lots of resources that JDBC is a typical example of Bridge design pattern. But they usually didn't tell the details, so I would like to know the details. According to my understanding:
Driver
interface is the bridge between theDriverManager
and the concrete JDBC driver classesConnection
interface is the bridge between theDriver
and the concrete JDBC connection classesStatement
interface is the bridge between theConnection
and the concrete SQL statement classesResultSet
interface is the bridge between theStatement
and the concete result set classes
Please modify if the my statements are wrong. Also I guess DataSource
interface is also a bridge, but I can not figure out that is a bridge between which classes
The Bridge pattern, as defined by the "Gang of Four", means decoupling an abstraction from its implementation so that the two can vary independently. In this context, it's not so much about bridging different classes together. Instead, the pattern illustrates the Open/Closed principle where the interface (JDBC API) stays the same, but new implementations (JDBC drivers) can be added and substituted for each other.
What this means is that data access code using JDBC only needs to depend on the API interfaces such as
Connection
,Statement
orResultSet
, instead of caring about the actual database system the application is connected to. JDBC will bridge the application to the database that's used in the environment the application is deployed to. For this reason, you can run the same code (using JDBC abstractions) against different RDBMS, and only the JDBC driver (implementation) needs to change.Added by RUI: http://www.informit.com/articles/article.aspx?p=29302