Should controller know about view?

Should controller know about view?

Your intuition that the view should not know about its controller is correct. Your controller should know about the button and how to react to it being tapped. That’s why a controller has button IBOutlet s to tell the button to e.g. change its title or enabled state. And it has button handlers to react to UI events.

Can view directly interact with model in MVC?

You can’t directly move from View to Model. First, you have to submit data to the Controller and then pass it to Model. To pass the data from View to Model, you have to follow these three steps: Submit HTML form to a Controller.

When should I use model view controller?

Model–view–controller (usually known as MVC) is a software design pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements.

Can you have a controller without a model?

From that point of view, it makes sense for the controller to be the one that controls references to the view and model. You can’t really have a controller without a Model and a View, however it makes a lot more sense to just have a View or just have a Model (for example, in unit testing).

Why is model-view-controller so important?

Because all client requests and responses go through the controller, there is a centralized point of control for the web application. This helps when adding new functionality. Code that would normally need to be put in every JSP page can be put in the controller servlet, which processes all the requests.

What’s the difference between a controller and a model?

A controller should only contain the bare minimum of logic required to return the right view or redirect the user to another action (flow control). Everything else should be contained in the model. In general, you should strive for fat models and skinny controllers. Your controller methods should contain only a few lines of code.

How are controller and view independent of each other?

The controller merely translated user interface events (e.g. a button press) into calls to the model. So the controller and view depended on the model, but were independent of each other. The model was independent of both. This allowed multiple views and controllers to work on the same model.