Adam Bien's Weblog

Tuesday Mar 17, 2009

Are EJB Naming Conventions Still Needed?

Since the advent of EJB 3.X I don't use the Local/Remote naming schemes for business interfaces any more. The EJB client is only interested in the functionality and not the distribution or other infrastructural settings. The business interface is therefore just a POJI - without any dependency on the EJB API or infrastructure:

public interface CrudService {

}

The EJB implements the interface and exposes it with the @Local annotation. 

@Stateless
@Local(CrudService.class)
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class CrudServiceBean implements CrudService {
}

I actually thinking about getting rid off the suffix Bean as well. It would be much better to emphasize the actualy responsibility and name after it e.g. a JPACrudService. It is already annotated with the @Stateless annotation - so it is obviously a Bean. In my opinion interface naming schemes are unnecessary in general.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Kommentare:

Exactly. I am not an fan of naming conventions either. Especially when you name your Beans "ServiceBeans" and put them in a "beans" or "services" package. That is so redundant. I think the naming conventions are mainly for the fact that you create classes that you would never create, if the framework didn't force you to. That is where the old OO design rule does not work "if you can't name it, don't write it". :-)

Gesendet von Thomas am March 17, 2009 at 11:10 PM CET #

Yes, it is needed specially for EJBs. In an application, not all classes (specially service classes) are 'EJBs. So do Programmers don't need to write EJBs if other more simple objects can be used. So it is better to have these differentiated by whether they have the suffix 'bean' or not. In maintenance projects like those maintained by programmers who did not do the original, the 'bean' suffix is a useful indicator. The annotation only helps in the declaration and does not provide a naming indication of its being 'bean' when used away from its 'source', i.e. several classes or modules away....

Gesendet von Greg am March 19, 2009 at 03:32 PM CET #

Senden Sie einen Kommentar:
  • HTML Syntax: Ausgeschaltet
Interviews/About
My Recent Book
Java One 2009
CommunityOne East N.Y.C
JavaONE 2008 Interview
Search
...the last 150 posts
...the last 10 comments
greenfire.dev.java.net
Links
my.netbeans.org
Visitors
License