google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

Decorators #307

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
public interface SomeInterface {
  void someMethod();
}
public class SomeImpl implements SomeInterface {
  public void someMethod() {
  }
}
pubilc class SomeDecorator implements SomeInterface {
  private SomeInterface next;
  public SomeDecorator(SomeInterface next) {
    this.next = next;
  }
  public void someMethod() {
    next.someMethod();
  }
}
currently, it is very hard to bind like:
new SomeDecorator(new SomeImpl());

My solution is here:
http://javaonhorse.googlecode.com/svn/branches/pre-0.1-taowen-spike-2/javaonhors
e-auxiliary/src/main/java/com/google/inject/chain/

I think it complement Multibinder, when ordering of invocation is required.

Original issue reported on code.google.com by tao...@gmail.com on 8 Jan 2009 at 9:34

GoogleCodeExporter commented 9 years ago
here is a example usage of the ChainModule:
http://javaonhorse.googlecode.com/svn/branches/pre-0.1-taowen-spike-2/javaonhors
e-auxiliary/src/test/java/com/google/inject/chain/multiple_modules.java

Original comment by tao...@gmail.com on 8 Jan 2009 at 9:36

GoogleCodeExporter commented 9 years ago
I updated my implementation quite alot. now
http://javaonhorse.googlecode.com/svn/branches/pre-0.1-taowen-spike-2/javaonhors
e-auxiliary/src/main/java/com/google/inject/
includes 4 kinds of special abstract module to bind SetOf<T> (same as 
Mutlibinder),
ListOf<T> (ordered), ChainOf<T> (impl decorated by a chain of decorators),
DecoratorFactoryOf<T> (decorators only, allow user to choose the impl to 
decorate
with). The value of these four kinds of modules is, it provides a extension 
model to
Module. If I provide a SetOf<T> in my binding, that means other module can bind 
same
SetOf<T> to participate into my configuration. So in my usage, I allow other 
modules
to "plug in" my modules in four ways:
bind a optional binding
add element to list
add element to set
decorate more decorators in chain

Original comment by tao...@gmail.com on 12 Jan 2009 at 2:28

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 26 Apr 2009 at 9:23

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 26 Apr 2009 at 9:43

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 27 Apr 2009 at 6:10