Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller in MVC design pattern

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 ?

like image 683
sadia zar Avatar asked Nov 20 '25 14:11

sadia zar


2 Answers

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...

like image 173
matt_roo Avatar answered Nov 23 '25 05:11

matt_roo


One of the main 'drivers' behind the separated presentation patterns is testability. A controller allows presentation logic to be tested.

like image 38
David Osborne Avatar answered Nov 23 '25 07:11

David Osborne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!