Questions tagged [controller]

The controller tag is used with questions involving the controller component of the Model View Controller (MVC) design pattern. The controller component accepts input, usually from a user interface, and issues various change and modification requests to the model component and/or the view component controlling the data of the model and how the data is presented. In some cases controller and view are combined into a single component.

The Model View Controller design pattern has several variations and the actual implementation details may vary between different programming languages.

There are variations such as the Model View Presenter design pattern. Also see this article, MVC or MVP Pattern - Whats the Difference.

MVC originally came out of the Smalltalk programming community at Xerox Parc in the 1970s. See this MVC at Xerox Park web page with a bit of history from Trygve Reenskaug.

35 questions
15
votes
1 answer

Controller calling multiple services

I have a few layers in my WebApplication: Presentation, Service, DAO, Domain. Services call DAO objects which reads data from a Database/File whatever. I have a Controller that needs to fetch data from different Services and set them as part of the…
Diyarbakir
  • 539
  • 2
  • 5
  • 12
8
votes
2 answers

Separation of concerns and other best practices across Controllers, Services, Providers and Stores in ASP.NET when building a REST web api

I am traditionally a desktop app developer, but circumstance has thrust me into the role of doing web client and corresponding REST api logic for a project I am involved in. Unfortunately, I'm a one-man-show, so my opportunities to learn new…
7
votes
1 answer

Clean Architecture - Controllers and Presenters

I am having a hard time trying to wrap my head around the relationship between Controllers and Presenters in Uncle Bob's Clean Architecture. In most of his videos, he talks too little about controllers, and a fair amount about presenters. The…
7
votes
4 answers

Should access control be implemented in controller or repository layer?

I've got a project with an HTTP API which returns data from a database. The layers it goes through to get to the API look like this: DB -> Repository -> Controller I'm looking to restrict the results which are returned based on the permissions of…
Joundill
  • 129
  • 8
5
votes
3 answers

Is Model a better place to set HTTP status code?

In MVC usually the controller sets whatever needs to be sent back to the client/View, including HTTP status code, e.g.: class Controller { public function get(Request req, Response resp) { if (this.model.get(req.getId()) { …
imel96
  • 3,488
  • 1
  • 18
  • 28
5
votes
2 answers

Should controller layer create model objects or they should be created by service layer?

I have a small application with classic layers Controller-Service-Dao. Controller actually is REST resource, which deals with JSON data. And the questions are: 1. where is the best place to create business objects from JSON primitives? Controller…
sphinks
  • 159
  • 1
  • 5
4
votes
1 answer

Should a Controller have a Model object as an attribute?

For context, this project is a personal budget program I am working on while I try to learn to use MVC patterns effectively. There is a SessionController that passes user commands to a MonthController. Each controller has a Parser that maps commands…
g_sue
  • 49
  • 3
3
votes
3 answers

Does the Controller contain get methods in MVC?

I am at the stage of implementing a my 1st ever view, after developing a Model and Controller, however there is a problem. I have been reading this article on MVC, which is what I have been aiming for when implementing, but I kind of went off-script…
3
votes
1 answer

where to put methods that manipulate objects

I have a controller method as follow: public class RoomsController { @RequestMapping(method = RequestMethod.GET, path="/v1/rooms/{name}") public ResponseEntity getRoomInformation(@PathVariable String name, @RequestHeader("Auth-Token") String…
Luiz E.
  • 133
  • 3
2
votes
4 answers

Can the presenter talk to to the controller?

in the clear architecture, what uncle bob suggested. I have a lot of questions about how to correctly distribute the responsibility. it seems that there is no relationship between controller and presenter. the controller's job is to take the input…
2
votes
0 answers

Packages, a controller class, and coupling vs cohesion

So I'm building my first application, in Python, and some issues have cropped up because of the lack of interfaces (I.e. explicit type declaration) My design involves several homebrew packages, and I've been taught to reduce coupling by using a…
user309290
  • 21
  • 3
2
votes
1 answer

Spring Restful API - Controller strategy

We are developing a new REST Api for our Spring MVC legacy enterprise web application (before this it was communicationg with Adobe Flex frontends). As a general rule we stated that we were creating a @RestController for every model we have in our…
frankieta
  • 121
  • 2
2
votes
2 answers

writing a controller file in Python

I need some advice on my idea to write a controller file in Python, and not like the C in MVC type controller but a more simpler idea. Just a Python script that controls the operation of some other Python scripts. I will outline the idea, and any…
jonathan
  • 129
  • 1
  • 3
1
vote
2 answers

How to properly implement Rest Controllers to handle overlapping entities?

I have: A User entity. A Poll entity. Relationship: User creates polls. Use-case: When an arbitrarily user is clicked his/her profile is loaded and shown. The profile includes a list of polls created by the clicked user. Which of the following…
1
vote
2 answers

Should a single method in a service class perform multiple operations for its controller?

Let's say I have a controller called MessageReceiverController which is a controller of an API that other services can call and include messages in the requests. For each of the messages the controller receives, it will process it and then send it…
xenon
  • 887
  • 1
  • 6
  • 9
1
2 3