MVC: Actions on one controller vs multiple controllers

Webnoob

Member
Joined
Jul 6, 2016
Messages
16
Hi all, noob here... I am starting off with MVC. I see in the examples they use multiple actions on one controller. Each action returns a View. At what point do you actually use another controller, because it looks like you can do all the pages as actions on one controller?
 

Solitude

Executive Member
Joined
Jul 23, 2008
Messages
7,312
The controllers are to keep things organised. For instance you can have a FileController (/File) and then do all your file related stuff in there.

As the site grows you don't want everything in the Home controller because it will become a pain to manage.

It's also nice to see the URL showing you which section you are in on the webpage.
 

Webnoob

Member
Joined
Jul 6, 2016
Messages
16
The controllers are to keep things organised. For instance you can have a FileController (/File) and then do all your file related stuff in there.

As the site grows you don't want everything in the Home controller because it will become a pain to manage.

It's also nice to see the URL showing you which section you are in on the webpage.

Ah ok tx for the quick reply
 

Kosmik

Honorary Master
Joined
Sep 21, 2007
Messages
25,665
We like doing a controller per business object. So if you have a customer object, you have a customer controller that deals with presenting all views and actions pertaining to it ( list, edit, delete, details etc )
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
The single do it all controller is nicknamed the god controller, because it's just a variation of the god object anti-pattern.

Fat controllers are considered God controllers when they take responsibility for handling too many requests. The pinnacle case is a site that has just the one controller handling all requests.
 

Webnoob

Member
Joined
Jul 6, 2016
Messages
16
[)roi(];17928635 said:
The single do it all controller is nicknamed the god controller, because it's just a variation of the god object anti-pattern.

Fat controllers are considered God controllers when they take responsibility for handling too many requests. The pinnacle case is a site that has just the one controller handling all requests.

Agreed SRP springs to mind..

We like doing a controller per business object. So if you have a customer object, you have a customer controller that deals with presenting all views and actions pertaining to it ( list, edit, delete, details etc )
That makes sense
 

flippakitten

Expert Member
Joined
Aug 5, 2015
Messages
2,486
It helps keep things modular.

So you can work on only a specific portion of the app and if it breaks (which does happen even after testing extensively), it only effects that one piece making it quick and easy to locate and fix.
 
Top