Where does the call to the database happen? Do I need to make a model object so as to obtain a DAO?
The actual code statements that make the direct call on the database are written in the DAO class.
The methods of the DAO are called by the business object (Model). In our example, this is an instance of Customer Manager.
The business methods of CustomerManager are called by the Controller.
Here is a sketch of a DaoManager:
public class DaoManager{
protected Connection connection = null;
protected PersonDao personDao = null;
public DaoManager(Connection connection){
this.connection = connection;
}
public PersonDao getPersonDao(){
if(this.personDao == null){
this.personDao = new PersonDao(this.connection);
}
return this.personDao;
}
}
In this sketch only a single DAO is obtainable, PersonDao, but you could easily add more DAO's along the same model.
Notice that the getPersonDao() method isn't synchronized even though it returns a kind of singleton. The DaoManager is not intended for sharing between threads, so no synchronization is inserted. Doing so would be quite easy though.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Could I be right if I would say that your CustomerManager is a sort of factory?
James Clark wrote:Each View has a Controller which mediates between the Model and the View.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss wrote:
The whole idea behind MVC is to decouple the three aspects of business behavior (Model), input channel (mouse, keyboard, voice...) and output channel (text, graphhic, sound...) so that they can be changed independently of each other.James Clark wrote:Each View has a Controller which mediates between the Model and the View.
Bauke Scholtz wrote:That each view has its own controller is not always right. In for example JSF there is only one controller.
Gregg Bolinger wrote:
Ilja Preuss wrote:
The whole idea behind MVC is to decouple the three aspects of business behavior (Model), input channel (mouse, keyboard, voice...) and output channel (text, graphhic, sound...) so that they can be changed independently of each other.James Clark wrote:Each View has a Controller which mediates between the Model and the View.
Unfortunately, that is nearly impossible. The view and the controller always become tightly coupled.
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Ilja Preuss wrote:The View is well allowed to listen directly to the Model and depict changes there directly, without any mediation by the Controller.
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vijitha Kumara wrote:
Ilja Preuss wrote:The View is well allowed to listen directly to the Model and depict changes there directly, without any mediation by the Controller.
I think you mean, for the view to display (Customer)data it needs to access the Model (in this case Customer) ?
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Don't get me started about those stupid light bulbs. |