Reputation: 849
public abstract class BaseDAO<T extends BaseDTO> {
public Integer create(T dto) {
}
public Integer update(T dto) {
}
public Integer delete(T dto) {
}
}
public class JobDAO extends BaseDAO<JobDTO> {
public JobDAO(Connection conn) {
super(conn);
}
@Override
public String getDBTableName() {
return "JobTABLE";
}
}
public class BaseDTO {
protected Integer ID;
public Integer getID() {
return ID;
}
public void setID(Integer ID) {
this.ID = ID;
}
}
public class JobDTO extends BaseDTO {
Integer employerID;
//getter
//setter
}
public class Job_GUI extends javax.swing.JFrame {
//GUI properties
}
I am trying to understandModel, View, Controller
Convention and I want to applyMVC
to above class structures I have which consist of Data Transfer and Access Objects. What I'm failing to understand, is my structure above MVC? if so, what is the model? I'm guessing the DTO are themselves Model
. Job_GUI is a View
which I know already, but what is the Controller
??
I want to directly write the actionPerformed
codes in the Job_GUI itself, something like this snippet to create a job in db:
JobDAO jdao = new JobDAO(conn);
//create object jobDTO to hold all form values to be passed to JobDAO
final JobDTO jobDTO = new JobDTO();
//populating JobDTO with values from form
jobDTO.setEmployerID(id);
jobDTO.setDescription(description.getText());
jobDTO.setTitle(txtTitle.getText());
jdao.create(jobDTO);
but should the above be in the Job_GUI
class itself or somewhere else. If I were to insert the above snippet in Job_GUI
am I moving away from the MVC convention as such? Where would you put the above snippet? The confusion lies in identifying which is the controller
class out of all that I have if I were to use the DTO
,DAO
Design Pattern
for database interaction.
Upvotes: 3
Views: 4948
Reputation: 10667
JobDAO jdao = new JobDAO(conn);
//create object jobDTO to hold all form values to be passed to JobDAO
final JobDTO jobDTO = new JobDTO();
//populating JobDTO with values from form
jobDTO.setEmployerID(id);
jobDTO.setDescription(description.getText());
jobDTO.setTitle(txtTitle.getText());
jdao.create(jobDTO);
In above code you basically doing job of Controller because you assigning values to your DTO and then calling create method of your DAO. This is what Controller is supposed to do. So you are right on this part except one small correction :
JobDAO jdao = new JobDAO(conn); //not preferable
JobDAO jdao = new JobDAO(); //preferred inside Controller class
Will suggest you to keep connection specific code inside your DAO. Your Controller class shouldn't know about your DB connection. You can perform this inside your create/update/delete methods of DAO.
DAO where you actually interact with DB is part of MODEL in MVC.
Just keep in mind few things :
And as you mentioned that you are already clear with View. So i haven't put any explanation on that.
Upvotes: 3