Click on text below to jump to specific point in the video (except iOS)


This is John from caveofprogramming.com. We will look at a DAO factory within the data access object pattern. Since the last tutorial, I have taken the PersonDAO and filled in some SQL so it actually works. Also in my database I have got a log table as well as a people table so I have also created a LogDAO. Basically, to demonstrate this idea, we have a couple of DAOs now. We have LogDAO which deals with log table and PersonDAO that deals with person table.

To organize this a bit more, the DAO pattern can be like a pyramid with multiple layers some of which you may not have.
If you wanted to add a new layer, you can create a factory which will create these DAO objects for us.

So I am going to create a new class DAOFactory.
This will have a method getPersonDAO which will return a new PersonDAO and similarly we can have a getLogDAO. When we actually use these objects, in the controller. Now instead of code which works with PersonDAO for example, this code can use DAOFactory. The methods have to be static.

I have a class called Model I started with and I am not using it.
I will go on to use that class in a future tutorial, but I want to point out that a lot of this depends on what you need to do. A lot of programs wouldn't have a class called Model, and if it did it would be some specific model. It might even have multiple model classes. Think of the model as a package, and not a particular class. The controller uses the model, so it uses classes from the model package. It is not necessarily the case that the controller is just going to work with the Model class. So the different bits of the application - model, view and controller - each of them are not normally one class. They are more like packages.
Video outline created using VideoJots. Click and drag lower right corner to resize video. On iOS devices you cannot jump to video location by clicking on the outline.