vendredi 23 octobre 2015

CDI : Is @Decorator useful in real projects compared to classic decorator pattern

Env:
   Wildfly 9.0.1
   Weld 2.2.14

I am currently looking into the possibilities of using CDI @Decorator in our legacy code base wherever reasonable.

Looking at the spec and the java ee 7 examples, the CDI @Decorators seems to be

  • Defined at compile time. Well, at least the list of them
  • Objects can not be decorated at runtime like the classic Decorator pattern

To quote from the classic Pizza and Toppings example, one can create top-up pizzas of any depth at runtime. For example : new Cheese(new Ham(new Pepper(new LargePizza())))

Is this possible with the CDI @Decorator ? If not, what is the real use of the @Decorator where you have to declare the objects at compile time i.e. with @Decorator and @Delegate (and list of them in beans.xml)? May be i am missing something here.

Thanks in advance,

Rakesh

Aucun commentaire:

Enregistrer un commentaire