有什么解决的正确方法:什么是正确的模式?
Class A {
methodDoSomeOperation() {
ClassB b.someOperation(.....);
....
}
ClassB {
someOperation(....) {
if (this.someCondition) then{
ClassC c.anotherOperation(....)
} else {
ClassD d....
}
}
}
方法c.anotherOperation
需要很长的时间。我希望收到有关所选内容的通知:c.anotherOperation(....)
或d.....
用于在调用c.anotherOperation
之前显示在用户界面中。
是这样的:
someOperation(....) {
if (this.someCondition) then{
//notify ClassA what was selected and continue
ClassC c.anotherOperation(....)
} else {
ClassD d....
}
}
显然,可以以调用在ClassA
一些方法,但这种产生强耦合,混乱的逻辑。是否可以使用Spring的某些功能?
[春季批量](http://static.springsource.org/spring-batch/)提供条件开关取决于方法的结果,用于完全使用XML,而不需要相互了解的类。看看它是否适合您的项目 –