| Can I use inheritance for the Home interfaces? |
|
Let's look at an example: Let's assume we want to have a default create() for the Person bean. The Home must have the following signature:
public interface PersonHome extends EJBHome {
public Person create() throws ...;
}
Now let's say we want a default create() for the Employee bean too. We would like to have:
public interface EmployeeHome extends PersonHome {
public Employee create() throws ...;
}
This is not allowed in Java. The overriding method cannot
differ in the return type only. So, one may then try to avoid the overload on the return type
by simply inheriting the method in the base class:
public interface EmployeeHome extends PersonHome {
}
Oops! Now you have broken EJB compliance, which
states that the return type of a create() must be the
remote interface. Obviously, you have to change something. What needs to change is
the EJB specification, which needs to be enhanced to
support inheritance of home interfaces properly. This is
probably slated for EJB 2.0. For now,
you cannot inherit your home interfaces. Having said that, note that you can always inherit your
remote interfaces (as in the above). Your homes still
must be:
public interface PersonHome extends EJBHome {
public Person create() throws ...;
}
and:
public interface EmployeeHome extends EJBHome {
public Employee create() throws ...;
}
This is really the way to go until the EJB specification is
updated.
If there are a number of shared methods between the two intefaces, you can put the shared methods into a common base class, of course.
|