Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is MVC and what are the advantages of it? [closed]

I found What are mvp and mvc and what is the difference but it didn't really answer this question.

I've recently started using MVC because it's part of the framework that myself and my work-partner are going to use. We chose it because it looked easy and separated process from display, are there advantages besides this that we don't know about and could be missing out on?

Pros

  1. Display and Processing are seperated


Cons

  1. None so far
like image 318
Teifion Avatar asked Aug 25 '08 19:08

Teifion


People also ask

What is MVC and what are its advantages?

MVC, short for Model, View, and Controller, is a methodology or architectural pattern used for efficiently relating the user interface to underlying data models and organizing to relate the application code. MVC is primarily used to separate an application into three main components: Model, View, and Controller.

What MVC means?

In object-oriented programming development, model-view-controller (MVC) is the name of a methodology or design pattern for successfully and efficiently relating the user interface to underlying data models.


2 Answers

MVC is the separation of model, view and controller — nothing more, nothing less. It's simply a paradigm; an ideal that you should have in the back of your mind when designing classes. Avoid mixing code from the three categories into one class.

For example, while a table grid view should obviously present data once shown, it should not have code on where to retrieve the data from, or what its native structure (the model) is like. Likewise, while it may have a function to sum up a column, the actual summing is supposed to happen in the controller.

A 'save file' dialog (view) ultimately passes the path, once picked by the user, on to the controller, which then asks the model for the data, and does the actual saving.

This separation of responsibilities allows flexibility down the road. For example, because the view doesn't care about the underlying model, supporting multiple file formats is easier: just add a model subclass for each.

like image 187
Sören Kuklau Avatar answered Oct 02 '22 13:10

Sören Kuklau


Separation of concerns is the biggy.

Being able to tease these components apart makes the code easier to re-use and independently test. If you don't actually know what MVC is, be careful about trying to understand people's opinions as there is still some contention about what the "Model" is (whether it is the business objects/DataSets/DataTables or if it represents the underlying service layer).

I've seen all sorts of implementations that call themselves MVC but aren't exactly and as the comments in Jeff's article show MVC is a contentious point that I don't think developers will ever fully agree upon.

A good round up of all of the different MVC types is available here.

like image 20
Quibblesome Avatar answered Oct 02 '22 13:10

Quibblesome