取消委托方法

发布于 2024-10-25 23:01:28 字数 709 浏览 1 评论 0原文

我正在尝试从一个第三方库到另一个第三方库的转换(gwt-extgxt)。为了帮助最大程度地减少前期更改并确保一致性和可测试性,我们决定创建实现旧 API 并将其映射到新 API 的代理类。

例如,像 Panel 这样的东西现在可能是 ContentPanel。旧的面板可能有一个名为 setEl(String name) 的方法,现在应该映射到 setElement(String name)。为了实现这一点,我们创建了一个包含 ContentPanelPanel 类。然后在 Eclipse 中,我们调用 Source ->生成委托方法... 以创建两个 API 可能共有的方法。然后,我们创建的任何丢失或更改的 API 都存在于 Panel 类中,并传递到所包含的 ContentPanel 中的相应处理程序。完成此操作后,我们想要重构我们的类(基本上是内联),让所有内容直接调用“ContentPanel”上的方法,并在调用旧方法的每个位置使用我们在手工实现的方法中所做的任何魔法。

最好的方法是什么?我认为 Eclipse 中已经有一个重构可以处理这个问题,但我没有找到它。

当然,如果您认为有更好的方法来进行这样的迁移,我也愿意接受相关建议。

I'm trying to do a conversion from one 3rd party library to another (gwt-ext to gxt). To help minimize upfront changes, and to ensure consistency and testability, we decided to create proxy classes that implement the old API and map them to the new API.

For example, something like Panel might now be a ContentPanel. The old Panel may have had a method called setEl(String name) that should now map to setElement(String name). To facilitate this, we created a Panel class that contains a ContentPanel. Then in Eclipse, we called Source -> Generate Delegate Methods... to create the methods that both APIs might have in common. Then any missing or changed APIs we create by had in our Panel class and pass along to the appropriate handler in our contained ContentPanel. When we're done with this, we want to refactor out our class (basically Inlining) and have everything call the methods on 'ContentPanel' directly and use any magic we did in out hand implemented methods in every spot that the old method was called.

What is the best way to do this? I thought there was already a refactoring in Eclipse that could handle this, but I'm not finding it.

Of course if you think there is a better way to do a migration like this, I'm open to suggestions on that as well.

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

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

发布评论

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

评论(2

離人涙 2024-11-01 23:01:29

IntelliJ IDEA 具有 内联重构 这对于您的情况可能非常有用。不确定 Eclipse 有没有,但也许有一个插件可以内联?

IntelliJ IDEA has inlining refactoring which could be quite useful in your situation. Not sure Eclipse has one but maybe there is a plugin that does inlining?

南笙 2024-11-01 23:01:29

答案是:不。使用目标对象作为组件然后进行委托是错误的策略。我们最好让我们的代理扩展我们的目标 API,然后实现新 API 中缺少的任何方法并将它们映射到新 API。然后内联根据需要工作。

The answer is: don't. Using the target object as a component and then delegating was the wrong strategy. We were better off making our proxy extend our target API, then implementing whatever methods where missing in the new API and mapping them to the new API. Then inlining worked as needed.

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