取消委托方法
我正在尝试从一个第三方库到另一个第三方库的转换(gwt-ext
到 gxt
)。为了帮助最大程度地减少前期更改并确保一致性和可测试性,我们决定创建实现旧 API 并将其映射到新 API 的代理类。
例如,像 Panel
这样的东西现在可能是 ContentPanel
。旧的面板可能有一个名为 setEl(String name)
的方法,现在应该映射到 setElement(String name)
。为了实现这一点,我们创建了一个包含 ContentPanel
的 Panel
类。然后在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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?
答案是:不。使用目标对象作为组件然后进行委托是错误的策略。我们最好让我们的代理扩展我们的目标 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.