java - 从 Java 类中提取接口(interface)的自动化方法

标签 java interface refactoring

我有一组定义 API 的具体类,我想从 API 的实际实现中提取这些类的接口(interface)(即:本质上是类型层次结构和公共(public)方法)。

例如,如果 API 中的公共(public)类之一是

 public class Foo extends Bar {
     /* some fields which I don't care about */

     public void method() {
     /* implementation here */
     } 

     public void otherMethod() {
     /* implementation goes here */
     }

    /* some non public methods which I don't care about */

 }

我想分成一个接口(interface)和一个实现

public interface FooInterface extends BarInterface {
    public void method();
    public void otherMethod()
}

 public class Foo implements FooInterface {
  /* etc etc */
 }

有没有我可以使用的工具以自动方式进行这种分离,或者我是否必须推出自己的程序来完成这项工作?它需要是一种需要最少交互的工具。

最佳答案

我找到了解决方案!

Eclipse,支持重构脚本,脚本在 xml 中,但不是很人性化,但无论如何我已经生成了脚本,使 eclipse 执行所有重构。

有关eclipse 脚本重构的详细信息,look here并使用 eclipse 为您生成一些示例,以便您知道脚本应该是什么样子

关于java - 从 Java 类中提取接口(interface)的自动化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4622633/

相关文章:

java - 延迟 EL 未得到解决

java - 自动生成 ="false"在 datastore-indexes.xml 中被忽略

c# - 查看类型是否可实例化

java - 使用已实现的类调用接口(interface)参数方法时出错

typescript - 如何使用 VSCode 在 TypeScript 中输入 "extract interface from a class"?

java - 如何重构内部类MouseAdapter?

java - Spring 管理属性的最佳方式

java - Maven Cargo 不会停止容器

c# - 允许实现多少个接口(interface)?

c# - 逐步应用更好的设计