Slicing Controllers

Learn the concept of "slicing controllers" and why it is better to create more controllers than a few.

In most web frameworks, like Spring MVCModel View Controller in the Java world, we create controller classes that perform the responsibilities we have discussed previously. So, do we build a single controller that answers all requests directed at our application? We don’t have to. A web adapter may certainly consist of more than one class.

We should take care, however, to put these classes into the same package hierarchy to mark them as belonging together, as discussed in the chapter “Organizing Code”.

Number of controllers

So, how many controllers do we build? I say we should rather build too many than too few. We should make sure that each controller implements a slice of the web adapter that is as narrow as possible and shares as little as possible with other controllers.

Implementing AccountController

Let’s take the operations on ...