Is there any reason for making delegate when using EJB3? Because the only real benefit i see from delegate is that it allows to hide lookup and access details of EJB architecture. Well it also provides some decoupling but it's mostly unused, imho. With EJB3 we have injection so now i can just create a variable with @EJB annotation and use it as is. Do i still need delegates? Is this injection resource consuming? I mean if i use it in JSF's request managed beans may be it's still better to use delegates just to lessen these injection calls?
Thank you!
Disadvantages : Maintenance due the extra layer that increases the number of classes in the application.
The purpose of having annotations is to attach additional information in the class or a meta-data of a class within its source code. In EJB 3.0, annotations are used to describe configuration meta-data in EJB classes.
To facilitate test driven development, the EJB 3.0 specification allows you to use annotations to inject dependencies through annotations on fields or setter methods.
Like resource injection, you can inject Session bean references into another EJB or other managed class using annotations or deployment XML. If you prefer annotations you can use @javax. ejb. EJB annotations to inject either remote or local EJB references.
Let's recap the forces of the original business delegate pattern:
All these forces are still relevant today -- they are not necessary present in every project, but could.
The main change is that we don't need the business delegate to minimize coupling (the one in italic). Dependency injection solved the problem of lookup and access.
I like the analysis from Adam Bien: one of the point about coupling that is still not solved naturally are exceptions. Exceptions are now unchecked, but still existing. Whether the client is supposed to be completely shielded from EJB exceptions or not depends again on the forces present in the project.
In the case the business delegate pattern was introduced to solve the problem of lookup and access (which I suspect was the case for a lot of project), we effectively don't need it anymore. If the business delegate was meant for other reasons it can still makes sense.
PS: from my own experience, resource injection was never a performance problem (I always had a more serious performance issue elsewhere than the millisecond taken for the injection :)
Business Delegates were just a hack to hide the whole kludge with JNDI lookups and all the related cleanup and error catching. Resource injection came into J2EE through Gavin Kings Seam which basically follows the as-few-layers-as-possible and all configuration in one place principle. So forget about those old patterns and just use normal OO think.
My 2 cents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With