Curious about how MVC works?

these days because of frequently watching MVC (PHP) on the Internet and personally implementing some scripts, and looking at Laravel
, I found that MVC is a file that will look for a lot of FUNCTION
and then even FUNCTION will look for FUNCTION
. What"s the difference between this and writing on the same page?
won"t this slow down?

because when it reads the FUNCTION script (the first ROUTER)
and then through this ROUTER to find the second or even several later FUNCTION
, doesn"t it just keep looking for other scripts and finally RETURN back
, or is it really faster?

so it would rather be hundreds of files, but the script in each file has only a dozen or dozens of lines
, but to complete the function of a shopping cart, he may autoload the FUNCTION, in more than a dozen files and finally each FUNCTION will become a complete shopping cart (including VIEW)
after RETURN comes back. Is it faster to execute in this way?


MVC is a design paradigm , not to make the code faster, but to help manage complex applications and make the application process specification controllable.
it's even straightforward to say that a framework with MVC mode is never faster than a single file.
for modern programmers who pursue agile development , the extra overhead compared to the benefits of MVC mode is negligible


MVC mainly separates the data layer from the business layer and the view layer. MVC fundamentally forcefully separates them.
this advantage is:
1. Improve code reuse rate;
2. Improve the maintainability of the program;
3. It's good for team development;
is not about making code faster.


MVC is actually a design pattern whose layering helps manage complex applications and can focus on one aspect at a time. For example, focus on view design without relying on business logic. At the same time, it also simplifies group development, and different developers in enterprise development can develop views, controller logic, and business logic at the same time. It's more efficient this way.


to put it simply, the introduction of MVC is equivalent to a best practice, and its purpose is not to Quick , but to model the business and decompose roles, and to agree on different concerns , which is also conducive to object-oriented design. Just like the relationship between low-level languages and high-level languages, theoretically, the former (directly writing assembly or machine code) may be faster, while the latter will waste some performance by compiling, but high-level languages have greatly broadened the imagination of development. in the past, it was possible to write a program written by a boss on a plane, but now it can be written by ten bald code farmers. The reason is that high-level languages focus more on program logic than on hardware limitations (which liberates productivity). The same MVC model does the same thing. It separates controllers, models and views from each other, represents the most basic hierarchical idea, and is a classic strategy for solving complex problems (there are many layered strategies in IT, such as the 7-layer model of OSI and the 4-layer model of TCP/IP stack are typical examples). In addition, it is also a convention, that is, any program that complies with the MVC model (which may or may not use a framework), you can roughly understand the main working logic of the program as long as you follow the process of "getting user input from the controller , controlling the model change, and triggering update of the view". Therefore, compared with large chunks of Function, you can roughly understand the main working logic of the program. MVC has an advantage in organizing large programs, which is why it is used.

Menu