开发者

Undelegate Method

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 co开发者_如何学JAVAuld 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.


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜