What design pattern does the Drivermanager.getconnection () method characterize?

What design pattern does the Drivermanager.getconnection () method characterize?

What design pattern does the Drivermanager.getconnection () method characterize?

A.
DAO

B.
Factory

C.
Singleton

D.
composition

Explanation:
DriverManager has a factory method getConnection() that returns a Connection
object.
Note 1:A factory method is a method that creates and returns new objects.
The factory pattern (also known as the factory method pattern) is a creational design pattern. A
factory is a Java class that is used to encapsulate object creation code. A factory class instantiates
and returns a particular type of object based on data passed to the factory. The different types of
objects that are returned from a factory typically are subclasses of a common parent class.
Note 2:
The method DriverManager.getConnection establishes a database connection. This method
requires a database URL, which varies depending on your DBMS. The following are some
examples of database URLs: MySQL, Java DB.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


thiago

thiago

I think it was Factory, but, doing some test I realized that really factory methods

Connection conn = DriverManager.getConnection(
“jdbc:hsqldb:hsql://localhost/”, “sa”, “”);

Connection conn2 = DriverManager.getConnection(
“jdbc:hsqldb:hsql://localhost/”, “sa”, “”);

System.out.println(conn == conn2); //prints false
System.out.println(conn.equals(conn2));//prints false