What goes into the “Controller” in “MVC”?

In the example you suggested, you’re right: “user clicked the ‘delete this item’ button” in the interface should basically just call the controller’s “delete” function. The controller, however, has no idea what the view looks like, and so your view must collect some information such as, “which item was clicked?”

In a conversation form:

View: “Hey, controller, the user just told me he wants item 4 deleted.”
Controller: “Hmm, having checked his credentials, he is allowed to do that… Hey, model, I want you to get item 4 and do whatever you do to delete it.”
Model: “Item 4… got it. It’s deleted. Back to you, Controller.”
Controller: “Here, I’ll collect the new set of data. Back to you, view.”
View: “Cool, I’ll show the new set to the user now.”

In the end of that section, you have an option: either the view can make a separate request, “give me the most recent data set”, and thus be more pure, or the controller implicitly returns the new data set with the “delete” operation.

Leave a Comment