In my application I have many types of entities - they have one common interface let say
public interface MyEntity {
String getCode();
}
Entites are being sent from fronted wrapped in some kind of request like
public interface MyRequest {
MyEntity getMyEntity();
String getOperationType(); // this can be one of 'CREATE', 'DELETE', 'UPDATE'
}
After performing my business logic, based on request's operation type and the entity that it includes, I need to run some post-process operation and this operation is custom for every pair of 'operation-entity' - for this I created a factory like
public class MyFactory {
private Map<MyKey<String, String>, MyOperation> postProcessors;
public MyOperation getOperationFor(String operation, String entityCode) {
...
}
public void addOperation(String operation, String entityCode, MyOperation operation) {
...
}
}
The problem is that I need to perform some additional postProcessing after every Operation, base on it's type, no matter what entity code I've received - e.g. "after every creation send notification to x@y.com" etc
My question is how to resolve this? I feel that adding to the factory additional Map<String, MyOperation>
and add/get methods for this is not a good idea - should I create additional factory? Or maybe I should create add/get methods but keep MyOperation
objects for operations with null in the place of entityCode
?
Aucun commentaire:
Enregistrer un commentaire