I want to ask that in MVC why do we need controller.why don't we just directly connect model and view.what would be the problem if we don't have controller ?
Separation of concerns, it makes the program more maintainable and allows us to add more functionality to different parts of the system without breaking other parts because they are independant of each other... https://en.wikipedia.org/wiki/Separation_of_concerns
So if your code for your domain and the logic of how it should be given to the view and then the code which handles the presentation of the data on the screen are all in the one place it makes it very hard for you to change parts of the domain code without having to change parts of the logic which moves it to the view and also the code which then presents it..with the controller we can move the logic into another class and make it independent of the view so when we are fixing or modifying our application we only need to concern ourselves with one part of the MVC model...
One of the main 'drivers' behind the separated presentation patterns is testability. A controller allows presentation logic to be tested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With