MVC Design Patterns – Is MVC Controller a Use Case Controller?

design-patternsmvcobject-orienteduse-case

In GRASP (http://en.wikipedia.org/wiki/GRASP_(object-oriented_design) ), a controller (use case controller) is defined as:

A use case controller should be used to deal with all system events of
a use case, and may be used for more than one use case (for instance,
for use cases Create User and Delete User, one can have a single
UserController, instead of two separate use case controllers)

I can see some similarities of this and MVC controller. However I don't see a standard guideline on how to design a MVC controller. Most of the time people just say it's up to the developer and the design of the application. So I'm wondering whether I can use guideline above to design MVC controller?

To be more specific, let's say an application has a page to display a list of products in a table. Each product is displayed as a row. Each row has a button to restock that product (or any other business operation that makes sense). So as I see, this page has 2 use cases (2 business operations): list products and restock product.

From the guideline above, probably I'll have 2 use case controllers for 2 use cases. Are those mapped to 2 MVC controllers? Or just need one Product controller with 2 actions for 2 use cases?

If just need one Product controller, how about a page that has many business operations in the same page? Soon the controller will become too big. Of course if a page has too many operations, it might not be a good UI design, but sometimes developers don't have a choice because clients want it that way to be convenient

Best Answer

You quoted the Wikipedia article out of context. It actually says:

The Controller pattern assigns the responsibility of dealing with system events to a non-UI class that represents the overall system or a use case scenario. A Controller object is a non-user interface object responsible for receiving or handling a system event.

A use case controller should be used to deal with all system events of a use case, and may be used for more than one use case (for instance, for use cases Create User and Delete User, one can have a single UserController, instead of two separate use case controllers).

So a Use Case Controller is a specific type of controller. It doesn't necessarily mean that's how you will organize your controllers, only that it is one way of organizing them.

Controllers can be organized by functional responsibility, department, or whatever organizational pattern makes the most sense for your particular requirements. There is no "standard" way of doing it.