基本上这两种方法合二为一:
例如:用户操作处理程序是使用映射和辅助注入创建的,即每个都需要一些静态绑定以及从请求动态创建的操作上下文。
class OpHandler { void handle()... }
class SendHandler extends OpHandler {
public SendHandler(DAL dal, SendContext context) { ... }
}
class ReceiveHandler extends OpHandler {
public ReceiveHandler(DAL dal, ReceiveContext context) { ... }
}
servlet:
onGet() {
op = resolveOp();
switch (op) {
SEND: create SendContext and pass it somehow to ioc.getInstance(SendHandler.class)
RECEIVE: create ReceiveContext and pass it somehow to ioc.getInstance(ReceiveHandler.class)
}
}