MVC Frameworks – Advantages of Using Business Logic in Model

frameworksmodelmvc

In an MVC framework i have often heard that use business logic in a model. But i think using the business logic in controller would run faster as view is directly connected to controller. I want to know what are the advantages of using a business logic in model?

Best Answer

The key is:

Separation of concerns

In an ideal world you want any given piece of code to do one thing and to do that well. So you want to try and avoid mixing up display logic and business logic and storage logic and everything else.

This separation provides a variety of benefits - testability (as suggested) is an important one (though to my mind it's almost a bonus), but also the fact that the code should be easier to understand at any given level and hence easier to maintain, that the business model/logic (in particular) is more portable (from web to native app) or that you can change the UX (say from MVC pages to a fully separated javascript app using a web API) - finally, if nothing else, the cummulative experience of a huge number of programmers tells us that it - separation of concerns - is a good thing.

On contemporary server hardware performance just shouldn't be an issue unless you're doing seriously funky stuff and then you don't want to have bound up in the user interface layers because you can't then attempt to deal with the performance issues in isolation.