用java编写接口的设计建议

用java编写接口的设计建议,java,Java,我不熟悉java,但我实际上很喜欢它,因为信不信由你,它正在改进我的编码方式。(我猜是因为它迫使您以面向对象的方式编写代码) 无论如何,我正在编写一个java库,它看起来像这样。在基础上有核心库,然后在其上构建一些工具包 现在,所有的工具包都有一部分共同的代码 例如,读取该工具包的配置文件。 示例:toolkitA/config/config.cfg config.cfg inputDir = /path/to/input outputDir = /path/to/output toolk

我不熟悉java,但我实际上很喜欢它,因为信不信由你,它正在改进我的编码方式。(我猜是因为它迫使您以面向对象的方式编写代码)

无论如何,我正在编写一个java库,它看起来像这样。在基础上有核心库,然后在其上构建一些工具包

现在,所有的工具包都有一部分共同的代码

例如,读取该工具包的配置文件。 示例:toolkitA/config/config.cfg

config.cfg
inputDir = /path/to/input
outputDir = /path/to/output



toolkitB/config/config.cfg

config.cfg
inputDir = /path/to/input
// no output here.. maybe this toolkit is just to analyze the input
问题是。。很多配置都是未知的,因为我仍在创建工具包的过程中,甚至我不知道将来会有什么工具包

到目前为止,代码流如下所示

 main--> readconfig-->parseconfig--> execute the source code with params. 
  parsed from the source parseconfig
我的关键问题是,由于这些配置文件位于工具包级别,因此这些配置文件根本不与源代码库连接。核心库忽略了一个事实,即这些参数实际上是由用户在配置文件中设置的。现在。。。也许是因为java,但我觉得这很肤浅。 我想要的是这样的东西

  main--> a core config file setter which reads and parses this tool kit config file --> 
  the core library then interacts with these  objects rather than the superficial level.
我如何做到这一点


(作为一个狂热的stackoverflow用户..我知道..这不是真正的“错误”相关问题,但我也不知道搜索什么或如何设置这样的配置..我所知道的只是我想如何实现这件事..:()

好吧…你的cfg文件就像这样,在

其次,您可以在类路径中发布这些配置,并使用

InputStream is = Object.class.getClass().getResourceAsStream(CONFIG_FILE);
Properties cfg = new Properties();
cfg.load(is);