Ian Lafuente wrote:But I see "Connection con = null;" and "PreparedStatement pst = null;". So it seems as if the interfaces are being used to create objects
The simplest way to put it is how is it possible that this code is creating Connection and PreparedStatement objects? I was always under the impression that interfaces cannot be instantiated, but rather implemented
Ian Lafuente wrote:Did you mean to write dogFactory.makeBarker() instead of barkerFactory.makeBarker()?
Ian Lafuente wrote:So in your example, the Pomeranian class, which implemented the interface Barker, contains all of Barkers methods?
barker is of the Barker type, and makeBarker() creates a new Pomeranian object which is then assigned to barker?
Going back to the code, "Connection con = null" and "con = DriverManager.getConnection(url,user,password);"
con is of type Connection and the getConnection() method in the DriverManager class will create a new object (of a class that implements Connection) that will be assigned to con?
What I don't understand is that looking at the Java API where DriverManager is defined (http://docs.oracle.com/javase/6/docs/api/) I don't see anywhere that indicates that the method getConnection() creates a new object (which would be of a class that implements Connection).