In this new series of articles, you will learn how to best design and optimize the Enterprise JavaBeans component, how to reduce RMI communication and JNDI access, and how to use Enterprise applications most effectively. In each article, Brett McLaughlin, the main authority in Enterprise Java programming, will provide best practices or design patterns. Many technical articles will be built on the previous articles. We recommend that you read these tip articles in sequence because they will help you build strategies and design methods that help your own enterprise application programming. In this (and the first) article, Brett demonstrates how the business interface mode can improve the remote object design.
If you have developed many EJB components, you are aware of the difficulties in Remote Object design. The core of the distributed EJB component is the ability to separate bean implementations (represented by Bean classes) from their interfaces (represented by remote or local interfaces. The interface is exposed to the client and is usually used in a JVM that is different from the actual implementation class. This means that at the code level, there is little dependency between them. It also means that some methods in the interface may not be implemented, and vice versa. For example, a utility method for implementing classes does not have to be placed on a remote interface.
Warning do not use this mode with Entity bean!
The business interface mode is only applicable to session beans and message-driven beans. This mode is not applicable to entity beans and should never be directly published to the application layer. In fact, the business interface mode stops working in the EJB 2.0 Entity bean because these classes are declared as abstract and therefore cannot be selected.
So far, nothing sounds unmanageable, but you need to realize that sometimes the mismatch in the method is unintentional, then the situation will change. When deploying a bean, you will realize that you need a new method. In this case, this situation naturally occurs. Add the method to the bean implementation class, but forget to add it to the remote interface. Now you have added the required features, but there is no way for remote users to actually access them. In this case, you need to introduce the Business Interface mode.
Note: The business interface mode is not the only method to avoid non-matching in the remote object design. Please read the supplementary article "alternative business interface mode" to learn other solutions.
Business interface mode
First, you need to write an interface that defines all business methods. This is very similar to a remote interface, but does not have the EJB semantics. Listing 1 shows a simple business interface of the Library object.
List 1. Library Service Interface
Package com. ibm. library;
Import com. ibm. library. exceptions. NoSuchBookException;
Import java. util. List;
Public interface ILibrary {
Public List getBooks ();
Public List getBooks (String category );
Public Book getBook (String isbn)