Imagine this scenario: you've written all the appropriate interfaces and
implementations for an EJB and now it's time to use it in client code. First
you get a bean reference. Everything is simple enough: use JNDI to get the
home interface, call a create method on it and catch all the possible
exceptions. Voilá, a usable EJB reference. No big deal. However, after
creating the bean and looking at the number of beans you want to use, you
realize you'll be doing the same thing over and over again. You shake your
head and say, "There has to be a better way to create these objects."
Fortunately, there is. Polymorphism and the reflection API provide a powerful
and flexible mechanism for obtaining EJB references.
Without using reflection or polymorphism, you'd obtain references something
like this: try {
// Use a helper method to get the JNDI context to use for lookups...
//... (more)