Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

main purpose of using mvc

Ive been doing a bit of research / reading into mvc recently and was just wondering what the main purpose is.

  1. is it as some people say to seperate the logic from the html
  2. or to create clean url's

i could be missing the point completely, but asp.net forms really seperates the logic from the html and if you just want clean url's why not use a mod_rewrite rule?

like image 956
andrew Avatar asked Oct 16 '09 13:10

andrew


People also ask

What is the benefit of using MVC?

MVC model returns the data without formatting: MVC pattern returns data without applying any formatting. Hence, the same components can be used and called for use with any interface. For example, any kind of data can be formatted with HTML, but it could also be formatted with Macromedia Flash or Dream viewer.

When should you use MVC?

Why Should You Use MVC? Three words: separation of concerns, or SoC for short. The MVC pattern helps you break up the frontend and backend code into separate components. This way, it's much easier to manage and make changes to either side without them interfering with each other.


1 Answers

MVC is a software engineering concept which is used more widely than just in ASP.net.

In a nutshell it encourages strong separation of:

  • business logic (the Model) the code which does all the brute force work behind the scenes; dealing with the database, performing large calculations; and
  • user interface logic (the View) the code which presents information to your users in a pretty way.

The C is for Controller - the ligaments that bind the bones of the model and the muscles of the views and allow them to communicate with each other cleanly.

You are correct that 'normal' ASP.net uses code-behind files so that page markup is kept separate from the code that generates that markup (in contrast to languages like PHP where code is embedded directly amongst HTML), but MVC ASP.net encourages even more separation in the ways I described above.

Take a look at this tutorial for a more detailed discussion of the pattern. Also take a look at this SO question


The MVC pattern has nothing to do with rewriting URLs. ASP.net MVC might make this easier but that is not by any means it's main purpose.

like image 70
Mark Pim Avatar answered Oct 01 '22 10:10

Mark Pim