Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should an Application Controller do?

I am a bit confused in what the application controller should do? Because I see the functionality will also exists in your MVP pattern to make the decisions which form should be shown when a button is clicked? Are there any good examples for Windows Forms that uses the application controller pattern?

There is a difference in the MVC(ontroler) and the Application Controller. I know the MVC(ontroller), I am not sure what is the responsibilities for an Application Controller, and how does it fit into a WinForms application. Martin Fowler also calls this the Application Controller pattern, surely it is not the same thing as the MVC(ontroller)?

like image 600
adriaanp Avatar asked Sep 23 '08 12:09

adriaanp


People also ask

What is an application controller?

A centralized point for handling screen navigation and the flow of an application.

What is the purpose of application controller in Rails?

A controller can thus be thought of as a middleman between models and views. It makes the model data available to the view, so it can display that data to the user, and it saves or updates user data to the model.

What is the main benefit that a class gets by inheriting from application controller?

By default, only the ApplicationController in a Rails application inherits from ActionController::Base . All other controllers inherit from ApplicationController. This gives you one class to configure things such as request forgery protection and filtering of sensitive request parameters.


2 Answers

I recently wrote an article on creating and using an ApplicationController in a C# Winforms project, to decouple the workflow and presenters from the forms directly. It may help:

Decoupling Workflow And Forms With An Application Controller

edit:
Archive.org has got a more readable copy of the article at this time.

like image 164
Derick Bailey Avatar answered Oct 02 '22 23:10

Derick Bailey


An Application Controller is a bit of a different beast than the controller used in MVC.

Martin Fowler's page on the Application Controller.

In the case of an MVP WinForms app, which seems to be what the question topic is about I think. You can put all the logic for "what form do I show now" into the Presenter, but as your application grows you're going to be duplicating a lot of code between Presenters.

Say you have 2 views that both have a button for "Edit this Widget", both of them would have to have logic to get a WidgetEditorPresenter and show the associated view. If you have an ApplicationController, you move that logic into the ApplicationController, and now you simply have a dependency in all your presenters on the ApplicationController and you can call appController.EditWidget() and it will pop up the correct view.

The application controller is an uber-controller that controls application flow throughout your system as you move from screen to screen.

like image 44
James Thigpen Avatar answered Oct 02 '22 23:10

James Thigpen