Slicing Controllers
Explore how to slice controllers into focused, small classes within a web adapter in hexagonal architecture. Understand why separating operations like account management into individual controllers improves maintainability, testability, and clarity. Learn to organize code to minimize shared models and promote precise naming, enabling easier parallel development and cleaner web applications.
We'll cover the following...
In most web frameworks, like Spring
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 an account entity within our BuckPal application. A popular approach ...