开发者

Provider recursion question

So, I have class Bar that should contains开发者_JS百科 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?


Use this instead of f in when invoking the Bar constructor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜