[英]How to Avoid repeating Code
I'm creating two Guice modules which handle different properties. 我正在创建两个处理不同属性的Guice模块。 The issue with this approach is that I have to duplicate the code two times in the implemenation.
这种方法的问题是我必须在实现中重复两次代码。 How can I avoid duplication and still be able to customize my bindings ?
如何避免重复并且仍然能够自定义绑定?
I was thinking of using Providers but can't find a cleaner way to do it. 我当时在考虑使用提供程序,但找不到更干净的方法。 Any direction would be appreciated
任何方向将不胜感激
public abstract class AConfModule extends AbstractModule {
/**
* {@inheritDoc}
*/
protected void configure() {
// Do some Confugurations
iConfigure();
}
protected abstract void iConfigure();
}
public abstract class BConfModule extends AbstractModule {
/**
* {@inheritDoc}
*/
protected void configure() {
// Do some Confugurations
iConfigure();
}
protected abstract void iConfigure();
}
Why not: 为什么不:
public abstract class AbstractConfModule extends AbstractModule {
/**
* {@inheritDoc}
*/
protected void configure() {
// Do some Configurations
iConfigure();
}
protected abstract void iConfigure();
}
public abstract class AConfModule extends AbstractConfModule { }
public abstract class BConfModule extends AbstractConfModule { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.