Well, like so many things in life, it's always good to be well organized. Models, views, and controllers are completely different pieces of code that help provide various functions for your overall project. Because of this, they are kept separate and organized.
Imagine if you are planning a program. You wouldn't put all your code in one function, would you? No, you divide them into separate smaller functions that solve very specific tasks. Similarly, as programmers, we are constantly looking for ways to split and split our large applications into smaller pieces. One of these organization design patterns is MVC, where a model (data) exists in one section, a representation (UI) exists in one section, and a controller (logic) exists in another section.
What problems does this solve? Well, just like the separation of functions solves the problems of readability, modularity and communication, just like MVC. Say, if you want to change a piece of code, you can solve it in a smaller subset, which is more or less isolated from most of the code. This allows you to add, modify or delete code more efficiently and logically. It also helps in testing, since such code is divided into groups, you can better cover your tests. It is also very important that you end up writing much less code.
Hope this helps.
source share