I wanna know, according to the MVC, where should I put my Connection Factory class?
controller package? util package? connection package? dao package?
Praveen Kumar M K
posted 4 years ago
In my opinion, MVC and Factory classes are 2 different paradigms and I necessarily dont see a connection from which one can generalize something.
MVC stands for Model(DAO and Data layer), View(JSP, HTML, Presentation layer) and Controller(The layer that connects View and Model). Its a classic design technique to build an application. It separates areas of concern, i.e., you have 3 separate layers, and it promotes loose-coupling, extensibility and re-usability. What that means is, is that you can work on any layer without affecting the other layers.
A Factory is a design pattern where in you delegate the creation of objects to a factory class. So in case I need to create an object, I can place a request to the factory and its the factory which will perform some logic and give me the created instance. This gives more of an authority to the factory and gets rid of spurious creation of objects.
So, you can use the factory class across any of the layers. If you wanted a factory for the DAO classes, you can use the DAOFactory class. If you want it at the controller level you can create a ControllerFactory and so on.
The way that I follow is to have a factory package and put all my factory classes into that package.