On Feb 9, 2010, at 4:53 PM, Jason Felice wrote:

> On Tue, Feb 9, 2010 at 6:24 PM, Brian Pontarelli <[email protected]> wrote:
>> Doesn't subclassing work? What issues are you having with that type of 
>> solution?
> 
> I have a bad allergy to subclassing for this kind of reason, although
> it does "work."  It would be nice if I could delegate instead.  Say
> via an EDSL declarative like:
> 
>  using(OtherModule.class);
> 
> or:
> 
>  using(new OtherModule(parameter));
> 
> (Since we have only single inheritance in Java, sub-classing will
> either break down by either failing to model a thing with two IS-A
> relationship.  Alternately, if you push everything into one super, it
> would become muddy since the super can't really delegate.)
> 
> I'm getting to the point where I'm thinking about how to build my
> processors from sets of parameterized dependencies.  It would be cool
> if I could:
> 
>  @Override
>  public void bind() {
>    using(new ConfigModule("fifth-third-ssl"));
>    using(SSLTransportModule.class);
>    using(Tandem610MessageFormatModule.class);
>    using(RRNReversalStrategyModule.class);
> 
>    bind(ITenderProcessor.class).to(IPProcessor.class);
>  }


To prevent deviating from the topic, I'll keep my views on public APIs and 
inheritance out of it. ;)  If you really can't modify the existing module, you 
really only have a couple of options:

        1. Inheritance
        2. Composition via micro-modules of sorts (seems like you are implying 
this in your example)
        3. ImplementedBy
        4. Write a completely new module that replaces the existing one
        5. Parameterize providers

I'd tend to lean towards #4 if you want to avoid inheritance because you don't 
trust the maintainer of the base class. It's overhead, but only 2-3 seconds of 
it via copy-paste. Personally, I use a combination of the first three. Most of 
my modules are really small and bind only a few things in separate methods. I 
use ImplementedBy a lot for my framework stuff and provide the ability to 
sub-class my modules as well.

Those are the only solutions I can think of. Someone else might have others.

-bp

-- 
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.

Reply via email to