OO Design...understanding MVC (edited)
Posted: Fri Jun 04, 2010 8:40 am
So, I should probably learn the basics of MVC before I try to shoe-horn stuff into what my understanding of it is.
Everything I read generalizes the concepts a bit too much and I end up with a half understanding.
Im not even sure what role the model even plays in the whole thing.
Like, lets have a use case where a user deletes a photo from a photo gallery.
First the user browses the photos determining which one to delete.
In this case, the gallery controller would have a browse case, which it contacts the database and gets the photos for the current page and category or what not.
It would then call the browse view which would display the photos however. What "logic" should be done by the control view? Should it loop through the array of images, parsing the data and displaying it as needed?
So now the user sees all the photos and they click the delete button on one.
That gallery controller would have a function for the delete case.
It would then access the database and delete the row.
It would then call the gallery delete view which would show a message about the successful deletion. Or perhaps it would call the browse view again and show the message there with the newly updated gallery??
Thats the type of stuff I dont get.
Also, I would assume I would want to have a photo object which itself handles the deletion, updating, adding of images to a photo. And perhaps even the display of said photo. How does this fit into the MVC design?
How does ajax fit in? The controller gets an ajax call and then passes the data back to the javascript in JSON for it to manipulate the dom?
Or could you have the controller get an ajax call, then contact the view, serialize the html and pass that back to javascript?
Everything I read generalizes the concepts a bit too much and I end up with a half understanding.
Im not even sure what role the model even plays in the whole thing.
Like, lets have a use case where a user deletes a photo from a photo gallery.
First the user browses the photos determining which one to delete.
In this case, the gallery controller would have a browse case, which it contacts the database and gets the photos for the current page and category or what not.
It would then call the browse view which would display the photos however. What "logic" should be done by the control view? Should it loop through the array of images, parsing the data and displaying it as needed?
So now the user sees all the photos and they click the delete button on one.
That gallery controller would have a function for the delete case.
It would then access the database and delete the row.
It would then call the gallery delete view which would show a message about the successful deletion. Or perhaps it would call the browse view again and show the message there with the newly updated gallery??
Thats the type of stuff I dont get.
Also, I would assume I would want to have a photo object which itself handles the deletion, updating, adding of images to a photo. And perhaps even the display of said photo. How does this fit into the MVC design?
How does ajax fit in? The controller gets an ajax call and then passes the data back to the javascript in JSON for it to manipulate the dom?
Or could you have the controller get an ajax call, then contact the view, serialize the html and pass that back to javascript?