是否可以在 GWT 中重载异步回​​调?

发布于 2024-09-29 06:29:25 字数 317 浏览 3 评论 0原文

我在服务器端有一个重载的查询方法。我想知道是否可以根据方法签名重载异步回​​调?或者是否建议定义两个不同的异步回调?这是我在服务器上的两种方法。

public String fetchInADay(String startTime, String endTime) {}

public String fetchInADay(String startTime, String endTime, String type) {}

顺便说一句,请评论:

如果我我需要进行两个不同的回调,这不是违反OO原则吗?

I have an overloaded query method on the server side. I wanted to know if I can overload the async callback, depending upon the method signature? Or is it advised to define two different asyncallbacks? These are my two methods o the server.

public String fetchInADay(String startTime, String endTime) {}

public String fetchInADay(String startTime, String endTime, String type) {}

As an aside, Please comment:

If I am required to make two different callbacks, isnt this against the principles of OO?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情场扛把子 2024-10-06 06:29:25

在这种情况下,无法重载异步回​​调,因为 onSuccess 方法将具有相同的签名。

您可以将同一个 AsyncCallback 对象传递给多个服务,但它无法判断哪个服务或函数调用了它。如果您希望不同的服务调用有不同的行为,则需要两个不同的回调。

There's no way to overload the async callback in this situation because the onSuccess methods will have the same signature.

You can pass the same AsyncCallback object to multiple services, but it won't be able to tell which service or function called it. If you want different behavior for your different service calls, you need two different callbacks.

静若繁花 2024-10-06 06:29:25

我假设您计划重用 onSuccess(String result) 中实现的逻辑。无论您调用什么服务方法,这都可以正常工作。您甚至可以在多个调用之间共享同一个实例。

由于 javascript 是单线程的,因此多个异步调用的响应(onSuccess() 调用)不会相互干扰,因此您可以放心。但由于这些调用的异步性质,无法保证其回调的顺序。

I assume you plan to reuse the logic implemented in onSuccess(String result). This works fine independent of what service method you call. You could even share the same instance across multiple calls.

Since javascript is single threaded you're on the safe side that the responses (onSuccess() call) of multiple async calls won't interfere with each other. But because of the asynchronous nature of these calls the order of their callbacks won't be guaranteed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文