ABSTRACT EJBs Creating EJB beans by hand is a laborious task. But using a code generator to do the job often robs the developer of much-needed power. There are two major types of EJB beans, Entity beans and Session beans. Both are created by implementing an interface. Each interface requires half a dozen methods, which can be tiresome when none of the methods require any actual code. This is a perfect situation for an abstract class. The abstract class provides default implementations, leaving the developer to override them on the rare occasions. The code for AbstractEntityBean is: package com.generationjava.ejb; import javax.ejb.EntityBean; import javax.ejb.EntityContext; import java.rmi.RemoteException; public abstract class AbstractEntityBean implements EntityBean { private EntityContext context; public void ejbActivate() throws RemoteException { } public void ejbLoad() throws RemoteException { } public void ejbPassivate() throws RemoteException { } public void ejbRemove() throws RemoteException { } public void ejbStore() throws RemoteException { } public void setEntityContext(EntityContext e) throws RemoteException { this.context = e; } public void unsetEntityContext() throws RemoteException { this.context = null; } public EntityContext getEntityContext() throws RemoteException { return this.context; } } The void methods are implemented by doing nothing, while the entityContext property is dealt with through a private EntityContext attribute. The AbstractSessionBean looks much the same: package com.generationjava.ejb; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import java.rmi.RemoteException; public abstract class AbstractSessionBean implements SessionBean { private SessionContext context; public void ejbActivate() throws RemoteException { } public void ejbPassivate() throws RemoteException { } public void ejbRemove() throws RemoteException { } public void setSessionContext(SessionContext e) throws RemoteException { this.context = e; } public SessionContext getSessionContext() throws RemoteException { return this.context; } } Again, the void methods are dealt with by ignoring them, while a private SessionContext is added to deal with the sessionContext property. By having an abstract set of classes, the effort required to develop a new EJB bean decreases. Occasionally a different implementation of a method is required, or the bean may extend another class. But in the majority of cases an abstract bean will save a developer much effort. -------------------------------------------