Understand MVC Pattern?

When building web apps, is the MVC design pattern always best?

  • I'm in the planning stages of a new web app and, out of habit, I was thinking of building it in typical MVC fashion. But I got to wondering if MVC is always the best choice? How would I know if it wasn't? If I don't use MVC what would I use? Just wondering.

  • Answer:

    This is one of my favorite job interview questions to ask. The MVC paradigm is a pretty good choice for webapps, generally.  You may choose to avoid it for headless processes (back end stuff, cron jobs, etc) and one off scripts.  If you are in the situation where you need raw speed, while you may implement your code using an MVC *paradigm*, you may wish to avoid  MVC *frameworks* as they are by nature optimized for maintainability and readability rather than performance.  This is also true when you have very specific implementation needs, as any existing framework is generalized to be useful to the maximum number of users. You will usually do fine by starting with an MVC framework: as you scale, you will add to, rewrite, and code around the framework until it meets your needs. In summary: not always but usually.

Laura Thomson at Quora Visit the source

Was this solution helpful to you?

Other answers

I generally believe in MVC. All applications you create are going to contain components of Control, Data and Presentation and the justification for separation makes a lot of sense. One problem I have with MVC is when building "sub-modules" you often require Control logic that get's either duplicated across Controllers, stuffed into Models and reused or Control logic ends up in the View. The best solution I've found to this is Using HMVC style frameworks. Basically you have a hierarchy of Controllers that are portable and each "sub-module" has it's own controller. Once you've already made a large product in MVC it can be a real pain to switch over to an HMVC approach so if you do end up going with MVC look into solutions that supports an HMVC.

Ken Struys

MVC is counter-intuitive at times, especially when the application is small. For a single page application, you are better off embedding the script into the page itself or for applications slightly larger in size and scope, there are micro frameworks that let you delegate tasks differently. If you have to expand the application codebase, then MVC is the key. I disagree with the premise that non mvc applications are performant or are difficuly to scale(considering the performance here); you scale a website, not a piece of code or a framework and the extra lookup call is generally optimized by the time your application goes into the web application server.

Sumit Bisht

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.