Slicing Controllers
In most web frameworks – such as Spring MVC in the Java world – we create controller classes, which perform the responsibilities we have discussed previously. So, do we build a single controller that answers all the requests directed at our application? We don't have to. A web adapter can 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 Chapter 3, Organizing Code.
So, how many controllers do we build? I say we should build too many rather than too few. We should make sure that each controller implements a slice of the web adapter that is as narrow as possible and that shares as little as possible with other controllers.
Let's take the operations on an account entity within our BuckPal application. A popular approach is to create a single AccountController that accepts requests for all operations that relate to accounts. A...