Page 1 of 1

About Question enthuware.ocpjp.v7.2.1189 :

Posted: Tue May 05, 2015 8:07 am
by Alina_Lapina
related with the question enthuware.ocpjp.v7.2.1126 :
The basic idea of the DAO pattern is that the code required to create, read, update, and delete (aka CRUD) an object from a data store is separated out from the object itself.
and

Code: Select all

public Student getStudent(int id) // create an object
public void createStudent(Student s) 
public void updateStudent(Student s)               // update an object
public void deleteStudent(int id)
isn't it look similar to:

Code: Select all

Connection c = DriverManager.getConnection("db url"); // => create an object
c.setAutoCommit(true);                                                // => update the object 
?

If yes, why it is a Factory pattern then?
If no, what's the difference?

Thanks in advance.

Re: About Question enthuware.ocpjp.v7.2.1189 :

Posted: Tue May 05, 2015 8:21 am
by admin
Connection is not business or domain object i.e. it has nothing to do with the purpose of the application. It doesn't have any application related data. It is just a tool that is used to manage the save/update of the domain objects. Connection itself is not the data that the application is interested in. Student object is the data that the application is interest in.

That is why, your example is not at all similar to the student example. And that is why it is not an example of DAO.

You should read about Factory pattern to see why it is a factory pattern.
HTH,
Paul.