简体   繁体   English

Java构建相互依赖的事件链

[英]Java building chain of events which depends on each other

I hava a set of methods of type boolean which are settings things up.我有一组boolean类型的方法,它们是设置。 Each method return true if busines logic was successfully executed and false if anything went wrong.如果业务逻辑成功执行,则每个方法返回true ,如果出现任何错误,则返回false I would like to break chain at first fail .我想在第一次fail打破链条。

Are there any good practicies?有什么好的做法吗?

ATM I am doing something like this: ATM 我正在​​做这样的事情:

if (taskIsDone(task) && taskGenerateReport(task) && taskReportIsDone(task) && taskProcessReport(task)){
    log.info("Processing of task {} is done", task.getName());
} else {
    log.error("Task {} finished with error", task.getName());
}

Something like this works in my dev env but if scenario when for any reason order of methods would change logic like this is useless.像这样的东西在我的开发环境中有效,但是如果由于任何原因方法顺序会改变这样的逻辑的场景是无用的。

Could anyone give me a hint how to make it right?谁能给我一个提示如何使它正确?

As the other people said, the order of execution is from the left to the right.正如其他人所说,执行顺序是从左到右。

In your case, I would call task.isDone() or task.generateReport() and so on, as it's related to the task which is in your case probably a domain object.在您的情况下,我会调用task.isDone()task.generateReport()等,因为它与在您的情况下可能是域对象的任务相关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM