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.


NEW: Java EE 7 Testing and Quality Workshop

A book about rethinking Java EE Patterns

Comments:

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". :-)

Posted by Thomas on March 18, 2009 at 12:10 AM 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....

Posted by Greg on March 19, 2009 at 04:32 PM CET #

I had the same question and hoped to find a answer here. Anyway, I am going without the 'Bean' suffix

Posted by Java Coder on September 12, 2011 at 10:59 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
Links
License