Given a collection of objects and an action id (there is a corresponding "action controller" class, which can be found with the id), what is the best way to organize mass action on the objects?
There are some twists though:
- an action is already implemented for a single object,
- action may need pre-checks. Those then warn the user, that the action in question can't be performed for certain objects
- mass action algorithm is not just a single action applied to each object. It's optimized, and also has some extras, compared to single action, and also extra constraints on eligibility of objects upon which the action can be performed
- mass action also has some metadata, which needs to be provided to UI even before pre-checks
- thus, mass action class (a) gives metadata on which parameters are needed, varying from action to action (b) can make preliminary checks for a set of objects (c) can attempt to perform mass action and return the result (for UI)
- it is desired to have single and mass action more or less in one place, so if it needs to be modified, only a single module or class needs to be changed
I am sure this situation is not unique, and the pattern for this probably already discovered in the wild. Current approach of having methods and mass-methods does the job, but is not quite elegant. Also providing metadata from the action class does not require collection of objects at all, so making it conditional when getting an instance of action controller does not feel good.
Note, that we abstract from what there is in the objects. Action on an object is not about calling some single method of an object. For simplicity, objects can be considered as just entities of just one type or even records.
Hoping for something more or less classic (for instance, not abrupt switch to CQRS).
Note 2. Action means domain-specific action at the backend.