When creating async apex classes (e.g. Batcheable, Queueable), especially classes associated with specific SObjects, what might be the best practice for where these async classes should be housed. Specifically, what solutions would best adhere to SOLID design principles and other concepts like Separation of Concerns.
Possible solutions I've been able to come up with thus far are as follows:
House the async class as its own class with a name prefix associating it with other related classes
Example:
AccountSpecificPurposeQueueable
, which can easily be found alongside other classes likeAccountService
,AccountSelector
, andAccountTriggerHandler
.Benefits: Seems to have stronger adherence to Separation of Concerns and single responsibility principle.
Drawbacks: Can lead to a glut of classes for a single object
House the async class as part of the service class
Example:
AccountService
class has a sub classAccountSpecificPurposeQueueable
.Benefits: Smaller number of classes, all functionality limited to service class
Drawbacks: Increased reasons to change service class, and more likelihood of merge conflicts due to multiple developers modifying the same service class.
My inclination is that solution one is most likely the most appropriate. I'm curious if this is correct, or if there are other and more suited solutions not listed here.