Business Interface EJB Design Pattern

When programming an EJB, you’ll write a bean interface (local or remote interface), a home interface (also local or remote), and a bean class. In the case of an entity bean, you’ll also need a primary key class if you don’t use a standard Java class for it.

Now, there is a relationship between your component interface (local or remote) and your bean (this bean will deliver the services defined in your component interface), but the bean class doesn’t implement his own component interface.

There are two good reasons for not doing this:

  • You would have to implement empty methods for all method signatures defined in javax.ejb.EJBObject or javax.ejb.EJBLocalObject. This is something the container should do, not your bean
  • You can’t pass a ‘this’ reference from your bean by mistake (that’s forbidden by the spec)

So, there’s actually no clean way to check proper business method implementation at compile time, nor is there a good way to ‘use’ the local or remote interface when implementing the business logic.

The Business Interface Pattern is an EJB design pattern that solves this problem.

Instead of extending your component interface directly from javax.ejb.EJBObject or javax.ejb.EJBLocalObject, you extends also from a standard java interface (the business interface), which holds all your plain business methods (just as you would do for a java interface for a non-ejb type).

So, instead of coding like this:
import javax.ejb.EJBLocalObject;

public interface MyComponentInterface extends EJBLocalObject {

public void myBusinessMethod ( String parameter );


you split this up, doing something like this:
public interface MyComponentBusinessInterface {

public void myBusinessMethod ( String parameter );

import javax.ejb.EJBLocalObject;

public interface MyComponentInterface extends EJBLocalObject, MyComponentBusinessInterface {


So, your component interface itself is actually empty. It is merely an aggregation of the necessary EJB methods and your business methods.

Archived: Uncategorized