Questions tagged [mvc]

MVC (Model-View-Controller) is a software architecture pattern that enforces separation of concerns.

MVC (Model-View-Controller) is a software architecture pattern that enforces separation of concerns. By isolating these components development, testing and maintenance can occur independently, reducing dependencies in the code.

Model

The model concerns itself with how the data is stored, retrieved and the business concepts that derive from the data should be interpreted.

View

The view concerns itself with how the data is presented, formatted and interacted with.

Controller

The controller concerns itself with the rules for how the view may change the model, what information can be accessed and what changes are allowed to be made.

948 questions
339
votes
14 answers

Should you write your back-end as an API?

I had a heated discussion today about our MVC application. We have a website written in MVC (ASP.NET), and it usually follows the pattern of do something in the view -> hit the controller -> controller builds a model (calls a Manager that gets the…
NibblyPig
  • 2,995
  • 3
  • 16
  • 19
222
votes
10 answers

What is MVC, really?

As a serious programmer, how do you answer the question What is MVC? In my mind, MVC is sort of a nebulous topic — and because of that, if your audience is a learner, then you're free to describe it in general terms that are unlikely to be…
Nicole
  • 28,111
  • 12
  • 95
  • 143
87
votes
4 answers

Is it bad practice that a controller calls a repository instead of a service?

Is it bad practice that a controller calls a repository instead of a service? To explain more: I figure out that in good design controllers call services and services use repositories. But sometimes in controller I don't have/need any logic and just…
mohsenJsh
  • 1,237
  • 1
  • 10
  • 15
78
votes
7 answers

Why should I use an MVC pattern?

It seems everyone doing web applications nowadays wants to use MVC for everything. I find it hard to convince myself to use this pattern, however. I understand the general idea is to separate the backend logic from the frontend that represents the…
Billy ONeal
  • 8,073
  • 6
  • 43
  • 57
77
votes
5 answers

Why put the business logic in the model? What happens when I have multiple types of storage?

I always thought that the business logic has to be in the controller and that the controller, since it is the 'middle' part, stays static and that the model/view have to be capsuled via interfaces. That way you could change the business logic…
Steffen Winkler
  • 905
  • 1
  • 8
  • 11
66
votes
13 answers

Why is it a good idea for "lower" application layers not to be aware of "higher" ones?

In a typical (well-designed) MVC web app, the database is not aware of the model code, the model code is not aware of the controller code, and the controller code is not aware of the view code. (I imagine you could even start as far down as the…
Jason Swett
  • 1,860
  • 1
  • 16
  • 19
66
votes
14 answers

Isn't MVC anti OOP?

The main idea behind OOP is to unify data and behavior in a single entity - the object. In procedural programming there is data and separately algorithms modifying the data. In the Model-View-Controller pattern the data and the logic/algorithms are…
Random42
  • 10,370
  • 10
  • 48
  • 65
62
votes
8 answers

MVC Architecture -- How many Controllers do I need?

I have been coding for a while, but mostly scripts and simple applications. I've moved into a new role where it is all about developing Web Apps and using a proper MVC architecture, so I am desperately trying to learn about all that very quickly. I…
Jeff
  • 1,854
  • 3
  • 16
  • 19
53
votes
3 answers

Where to put business logic in MVC design?

I have created a simple MVC Java application that adds records through data forms to a database. My app collects data, it also validates it and stores it. This is because the data is being sourced online from different users. the data is mostly…
51
votes
7 answers

Why does everyone put controllers in one folder and views in another?

I'm getting ready to take the bend out of asp and into an mvc framework, asp.net mvc or nancy. Wherever I go, I see folders for controllers/modules and folders for views. Is this just a pavlovian reflex of tidying things away by type, or is there…
bbsimonbb
  • 739
  • 1
  • 6
  • 12
50
votes
2 answers

What are the improvements of MVP over MVC?

I have read for three days about the Model-View-Controller (MVC) and Model-View-Presenter (MVP) patterns. And there is one question that bothers me very much. Why did software designers invent MVP, when there already was an MVC? What problems did…
Victor
  • 611
  • 5
  • 7
50
votes
11 answers

Best practice or design patterns for retrieval of data for reporting and dashboards in a domain-rich application

First, I want to say this seems to be a neglected question/area, so if this question needs improvement, help me make this a great question that can benefit others! I'm looking for advice and help from people who have implemented solutions that solve…
richard
  • 3,325
  • 2
  • 25
  • 39
49
votes
6 answers

How much business logic should be allowed to exist in the controller layer?

Sometimes we have some business logic represented in the controller code of our applications. This is usually logic that differentiates what methods to call from the model and/or what arguments to pass them. Another example of this is a set of…
jellyfishtree
  • 1,201
  • 1
  • 9
  • 15
45
votes
5 answers

What are the downfalls of MVC?

I've been using MVC/MV* since I started actually organizing my code years ago. I've been using it so long that I can't even think of any other way to structure my code and every job I've had after being an intern was MVC based. My question is, what…
Oscar Godson
  • 829
  • 1
  • 7
  • 12
42
votes
11 answers

Is the 'C' in MVC really necessary?

I understand the role of the model and view in the Model-View-Controller pattern, but I have a hard time understanding why a controller is necessary. Let's assume we're creating a chess program using an MVC approach; the game state should be the…
Anne Nonimus
  • 979
  • 1
  • 9
  • 10
1
2 3
63 64