First page Back Continue Last page Graphics
Bean Class Bases
Bean classes may have much redundant code
- Class must implement SessionBean or EntityBean
- Often, the methods are left empty
- All beans should hold
EJBContext in an
instance variable
Base classes can
simplify these classes
- “No-op”
implementations
- See notes
for source code...
Notes:
As you write bean classes for many beans you will notice certain requirements they all have in common:
They must implement either the SessionBean or EntityBean interface, requiring 4 or more methods; many (if not most) of them are left empty.
The code for capturing the context object in an instance variable is the same in each case.
You can simplify this code with a design technique used in other aspects of Java programming:
1. Define a class that implements the requisite interface with empty implementations.
2. If necessary, give that class additional functionality.
3. Use the class by subclassing it and overriding any methods you wish to use.
This is the technique behind the various “adapter” classes in java.awt.event as well as the GenericServlet class in javax.servlet.
Thenext page shows two base classes for beans that use this technique, followed by examples of their use...