Questions tagged [model-view-controller]

Model–View–Controller (MVC) is an architectural pattern, introduced in mid 1970-s in PARC into how to compose software interfacing also with user-interactions. For Microsoft ASP.NET MVC, please use [asp.net-mvc] or [asp.net-core-mvc] tag instead. For Spring MVC, please use [spring-mvc] tag instead.

Model–View–Controller (MVC) is an architectural pattern used in software engineering, since Palo Alto Research Centre released one such in mid 1970-ies, designed in Smalltalk-79 language.

The pattern isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing, portability and maintenance of each (separation of concerns).

Image which demonstrates typical collaboration of the MVC components:

MVC

Reference

The analogy

MVC can be metaphorically related to a TV. You have various channels, with different information on them supplied by your cable provider (the model). The TV screen displays these channels to you (the view). You pressing the buttons on the remote controls affects what you see and how you see it (the controller).

33635 questions
86
votes
12 answers

MVC: Where to put business logic?

First of all, I have seen many questions of this, but not enough reasoning behind that. If my question is not good enough and should be removed I'll understand. I have taken a look at, for example, this and a 45+ voted up answer says he advises you…
85
votes
2 answers

Embedded statement cannot be a declaration or labeled statement

I am trying to create a user using claim identity asp.net I get this error while creating claims identity user. ApplicationUser user = new ApplicationUser { EmailConfirmed = true, UserName =…
husseinbaalbaki
  • 901
  • 1
  • 6
  • 7
84
votes
4 answers

Differentiating between domain, model, and entity with respect to MVC

Can someone explain these 3 concepts and the differences between them with respect to an MVC framework along with an example. To me these appear almost equivalent, and it seems they are used interchangeably in some articles and not in others.
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
81
votes
4 answers

Sails.js vs Meteor - What are the advantages of both?

I've been reading a lot on Nodejs and its frameworks and recently finished my first full javascript frontend (using Angularjs). I've decided that my next pet project will be a Nodejs adventure using one of these two frameworks: Sails.js…
pedropeixoto
  • 1,633
  • 2
  • 27
  • 52
81
votes
11 answers

Are the roles of a service and a façade similar?

The more I read, the more confused I am. Note that all the question is related to how service and facades fit on the MVC pattern. My understanding is that a Facade is not a super-smart object, it is simply a way of exposing a simple interface/api…
79
votes
1 answer

Best practices of building a website using Node.js

I was wondering how one would go about developing a website from scratch with Node.js. I understand how I could possibly do it, but I am interested in the best design practice. I need this theoretical website to: Do a lot of AJAX Be very…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
78
votes
5 answers

How to add a hook to the application context initialization event?

For a regular Servlet, I guess you could declare a context listener, but for Spring MVC would Spring make this any easier? Furthermore, if I define a context listener and then would need to access the beans defined in my servlet.xml or…
teddy teddy
  • 3,025
  • 6
  • 31
  • 48
77
votes
2 answers

FLOW3 action parameters and arrays of objects

FLOW3 provides a convenient way to pass entities by ID in the URL, and get them automatically instantiated in the controller action's parameters: class PostController extends \TYPO3\FLOW3\MVC\Controller\ActionController { public function…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
77
votes
7 answers

Better to have huge Controllers, or many controllers, in MVC?

We are building a fairly large HR application in ASP.NET MVC, and so far our controllers are becoming quite large. For example, we have an Employee controller, and all employee views are included (Personal info, employee deductions, dependents,…
Beep beep
  • 18,873
  • 12
  • 63
  • 78
76
votes
2 answers

Fat models, skinny controllers and the MVC design pattern

I just read a blog post that explains MVC with a banking analogy. I have a few months of experience with web application development with an MVC framework (CakePHP), so I get the basics, but I began to see a theme that made me think I'm taking a…
ryonlife
  • 6,563
  • 14
  • 51
  • 64
75
votes
8 answers

Alternatives to the MVC

What are the alternative "design methods" to the Model View Controller? MVC seems to be popular (SO was built with it, I know that much) but is it the only method used?
Teifion
  • 108,121
  • 75
  • 161
  • 195
73
votes
6 answers

How can you organize the code for a game to fit the MVC pattern?

I'm a freshman in college going for my computer science degree... I've programmed plenty the last several years but just lately I've been getting more into theoretical ideas about organizing code, design patterns, differences in languages, etc. I…
Ricket
  • 33,368
  • 30
  • 112
  • 143
72
votes
6 answers

In Angular, how to redirect with $location.path as $http.post success callback

I am attempting to make a simple authentication service by sending a Post to a php file, I need it to load the home page partial on my ng-view when its successful. This is what I tried : function loginCtrl($scope, $http, $location){ …
George Ananda Eman
  • 3,292
  • 8
  • 28
  • 29
72
votes
7 answers

AngularJS client MVC pattern?

Until now I was mainly using Struts 2, Spring, JQuery technology stack for building web applications. The point is, that mentioned stack uses server side MVC pattern. The main role of web browsers was limited to a request/response cycle (+ client…
PrimosK
  • 13,848
  • 10
  • 60
  • 78
71
votes
4 answers

When do I call my class controller, manager or service?

Maybe it is obvious to you. I'm new to java (half year work) and I had a discussion with my collegues. I have troubles naming my classes according to their responsibilities. For that, my classes gain responsibilities they should never have. Can you…
MartinL
  • 3,198
  • 4
  • 18
  • 20