Isolating business logic in Ledger
February 12, 2022
We're in the process of building the application Ledger was designed for. There is a need for operations that are indirect to the APIs, for example deleting a ledger account. The place to put that logic isn't obvious. It involves multiple models and isn't always directly related to a request or a view, so it doesn't really belong in a controller. This comes up a fair bit and the usual approaches are to have the model engage other models (creating unwanted dependencies), make a specialized controller, or to put the logic in a helper class. But helper is often short for "didn't fit anywhere else". Helper folders wind up containing a grab bag of code. That doesn't seem like a good place to put core business logic.
We've heard other developers make the same observation about business logic that doesn't seem to belong in either models or controllers. Almost always the functionality pertains to business logic. So Ledger is introducing "Logic" classes. These bridge the gap between controller and model and will help limit models to retrieval, storage and interactions with related models.