提供者递归问题
所以,我有类 Bar
,它应该包含 Bars 工厂。
class Bar {
Collection<Bar> children;
Bar(BarFactory factory, Foo1 foo, Foo2 foo2){
}
addChild(Foo1 foo1){
children.add(factory.create(foo1));
}
}
class BarFactory {
Bar create(Foo1 foo1);
}
描述BarFactory时出现的问题。存在与其他对象相关的特定逻辑。我尝试使用 @Provides
机制,例如
@Provides
BarFactory provideLogicElementPresenterFactory(Dependence d){
final BarFactory f = new BarFactory(){
@Override
public Bar create(Foo1 foo1) {
Foo2 foo2 = null;//some logic
return new Bar(/*how pass factory here?*/f, foo1, foo2);
}
};
return f;
}
如何描述这种递归结构或者这个问题有替代解决方案吗?
So, I have class Bar
that should contains factory of Bars.
class Bar {
Collection<Bar> children;
Bar(BarFactory factory, Foo1 foo, Foo2 foo2){
}
addChild(Foo1 foo1){
children.add(factory.create(foo1));
}
}
class BarFactory {
Bar create(Foo1 foo1);
}
The problem in describing BarFactory. There are specific logic with dependencies from other objects. I've tried to use @Provides
mechanism, like
@Provides
BarFactory provideLogicElementPresenterFactory(Dependence d){
final BarFactory f = new BarFactory(){
@Override
public Bar create(Foo1 foo1) {
Foo2 foo2 = null;//some logic
return new Bar(/*how pass factory here?*/f, foo1, foo2);
}
};
return f;
}
How to describe such recursive structure or there is alternative solution for this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
Bar
构造函数时,使用this
而不是f
。Use
this
instead off
in when invoking theBar
constructor.