On Thu, Mar 18, 2010 at 4:31 AM, Jason Felice <[email protected]>wrote:
> > On Thu, Mar 18, 2010 at 12:19 AM, Fred Faber <[email protected]> wrote: > >> I think you'd be better off using a MapBinder. The boilerplate of guice >> essentially disappears, with only your specific configuration needing to >> consume a linearly incremental amount of code per new type. >> >> Code below. >> >> regards >> -Fred >> > > The use case which inspired the post has more complicated logic used to > decide the concrete implementation, where various case clauses inspect > different properties of a data bean which is the sole parameter. I was > trying to capture that with my contrived example (the 'inverted'), but > didn't think too much about it and missed the mark. > > Thinking about it some more, ideally, a generic way to dynamically produce > a provider which binds functional tests to resultant types would eliminate > the entire boilerplate class! It would be a neat extension to write. > Hmm... > At that point you would simply have a considerable amount of domain factory logic. The Guice boilerplate in itself is relatively thin. If the boilerplate is the injection of N providers, then that at least can be simplified to an injection of a Map<Class<? extends Foo>., Provider<Foo>>: your factory switches off at you had it written, and once it determines what class to return, it can easily return "providerMap.get(<class_of_foo>.class)". My point is that such dynamic introspection is a relatively custom domain concept orthogonal to the use of Guice. Yes, it could perhaps be embedded into the bindings. Another example is if you were to bind "Map<Predicate<YourBean>, Provider<Foo>>", and you could iterate over the keyset to determine which predicate matches a given YourBean in the Factory. But that it still requiring you to write the logic of the Predictes, and this should be extractable and testable. In any event, interesting discussion, thanks. > > (Speaking of which, I have another problem, which is the lack of canonical > "function" interfaces in Java, leading people to invent new ones each time > they need it. In Scala, we have Function0<RT>, Function1<RT,P1T>, > Function2<RT,P1T,P2T> traits. Is there any Java project which provides > these, plus perhaps the adapters for currying, functional composition, > adapting static methods and reflected Methods, etc? It's simple enough to > write, but again, it would be nice if there were something more > "canonical".) > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
