Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • Thanks for answering. Not sure if I understand your answer, but I'm not sure it answers exactly the question. I know what the job of the controller is, and that it's supposed to mediate between the model and the view. My question was if it's reasonable that often the controller mediates simply by delegating directly to the appropriate method on the model, when the view reports about a user action. Do you have an opinion regarding this? Commented May 3, 2014 at 18:12
  • In theory, it's possible. I don't know if it would be a good idea, but in theory it's possible. Edit: in theory it's not incorrect. If you didn't care about the return value of the function and various other things were already taken care of... but this is actually almost a code-smell to me, because it probably means that the code base suffers from low cohesion, and IMHO high cohesion is very important and perhaps more important than many other more popular principles. Commented May 3, 2014 at 19:41
  • I edited to point out that the model should be view AND controller agnostic. Commented May 3, 2014 at 20:46
  • I'll describe an example situation, please say if it seems to you like a correct MVC implementation: consider a word processor. The user clicks the Bold button on the GUI (the view) to make text bold. In reaction, the view calls controller.boldButtonClicked(). In the boldButtonClicked() method, the controller simply calls model.makeTextBold(). The model then carries out the logic needed to make text bold, and updates the view. Does this seem reasonable? The part where the controller simply delegates to the model? Commented May 3, 2014 at 21:52
  • It's going to be much, more complex than that fundamentally in your example. For example in the context of a word processor, the Controller layer probably has to do things like find out which characters in the document are highlighted and let the model know that. Commented May 3, 2014 at 23:29