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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With