noodle22
Programmer
- May 8, 2008
- 23
I am trying to set up an MVC based web site but I have very little experience with this pattern and am not sure that I fully understand it. I'm pretty sure that I am not doing this right so am I on the right track here?
My Model - A bunch of data objects populated directly from the database (using nhibernate). To get values from this model, I have a bunch of data accessor classes (ie UserDA is used to get a single user, all users, users with certain attributes, etc). Each data accessor has two interfaces, the first one is the model interface (ex IUserModel) and is used to get data. The other is a controller interface (ex IUserController) which is used to save data.
Since I am using a webpage and since my model is basically just getting/saving data to a database, I am not implementing any sort of observer pattern (at least not yet).
View - Is a webpage that has an instance of both IUserModel and IUserController. It uses the IUserModel to populate the page and IUserController to save changes in the database. The view does contain code for populating certain data objects before saving (should that be in the controller?)
This is confusing for me because
a) really, the model and controller code is in the same class (those that access the db)
b) I could in fact access both the model and the controller from any class by just doing IUserModel model = new UserDA() or IUserController controller = new UserDA(). I don't really have any sort of class that manages the creation/assignment of controller and model interfaces.
My Model - A bunch of data objects populated directly from the database (using nhibernate). To get values from this model, I have a bunch of data accessor classes (ie UserDA is used to get a single user, all users, users with certain attributes, etc). Each data accessor has two interfaces, the first one is the model interface (ex IUserModel) and is used to get data. The other is a controller interface (ex IUserController) which is used to save data.
Since I am using a webpage and since my model is basically just getting/saving data to a database, I am not implementing any sort of observer pattern (at least not yet).
View - Is a webpage that has an instance of both IUserModel and IUserController. It uses the IUserModel to populate the page and IUserController to save changes in the database. The view does contain code for populating certain data objects before saving (should that be in the controller?)
This is confusing for me because
a) really, the model and controller code is in the same class (those that access the db)
b) I could in fact access both the model and the controller from any class by just doing IUserModel model = new UserDA() or IUserController controller = new UserDA(). I don't really have any sort of class that manages the creation/assignment of controller and model interfaces.