Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which design pattern is used in jdbc connection?

Connection conn = DriverManager.getConnection(URL); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql);

Which design pattern is in use here ? We see each object returning a different object.

What would be some alternatives to the chosen design pattern ?

like image 614
JavaDeveloper Avatar asked Dec 16 '15 04:12

JavaDeveloper


1 Answers

Obviously not every code follows design patterns. But there are still things there that resembles some familiar patterns.

The whole JDBC architecture is actually a Bridge, it is an abstract concept which holds other abstractions that could be replaced separately.

The classes below implements some patterns.

DriverManager.getConnection(URL) seems like a static factory method to me, which is very common in Java frameworks.

Statement and Connection actually follows the same patterns, it is some sort of Unit of Work or Transaction pattern since it allows you to bulk statements together. But it also follows a Proxy pattern when it implements JDBC Wrapper interface.

ResultSet follows the Iterator pattern but it is also a Data mapper.

like image 185
ThePolisher Avatar answered Sep 18 '22 07:09

ThePolisher