MVC Framework – Understanding the Purpose of MVC

mvc

I've seen a lot of stuff that describes how it's done, but not a lot that tells WHY it's done. Is it just a way to keep the code readable, or is there a better reason?

Best Answer

It's about Separation of Concerns. Basically, you want your software components to do one thing, and one thing only. If your components start doing more than one thing, code gets hard to read, things become more complicated than they need to be -- basically an app turns into a big plate of Spagetti Code.

The Models contain the business logic, represent the things in your application. The views present the data to the user. The controllers decide what to do with the various user actions. When you stick to that, the code is easy to read because things are as simple as possible.

MVC is a popular pattern, but it's not the only one out there. MVVM is also popular. As long as you separate your concerns, pick any design architecture that suits you.

Related Topic