views:

2262

answers:

3

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)?

A: 

Personally I have no experience with MVP or winforms, but I have worked with MVC. I hope this is what you're asking, otherwise ignore my answer completely.

The C in MVC is responsible for more than just choosing the next view to be presented to the client. It holds most, preferably all, business-logic of the application, including performance of system tasks (such as logging and enforcement of permissions upon the flow of data from the model and to it).

Its primary task is, naturally, to serve the presentation layer above it and separate it from the model layer below while mediating between them. I guess you can think of it as the brain of the application.

Hope this helps,

Yuval =8-)

Yuval
+5  A: 

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.

James Thigpen
Great answer, at the time of my answer the OP was less clear as to what he wanted to know about.
Jim Burger
+3  A: 

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

Derick Bailey