File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes EJB Home uses Abstract factory or Factory Method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "EJB Home uses Abstract factory or Factory Method?" Watch "EJB Home uses Abstract factory or Factory Method?" New topic

EJB Home uses Abstract factory or Factory Method?

James Turner
Ranch Hand

Joined: May 10, 2004
Posts: 194
Hi guys,

I have read in many places that the EJB home uses the abstract factory or the factory method, I believe its the abstract factory that is in use, with only one object in the family of objects created by the factory.

It dosn't seem to be the factory method because there is no direct subclassing of this interface by the EJB (the create call is delegated but not via inheritance).

Can anyone clarify or provide any insight...



James<br />SCJP 1.4 - 92%<br />SCJD - 93%<br />SCWCD 1.4 - 95%<br />SCBCD 1.3 - 100%<br />SCEA - 92%
Erik Brakkee
Ranch Hand

Joined: Jun 21, 2004
Posts: 40

If I would have to choose between the two I would choose Factory Method, the reason being that the Home interface is not only about creating objects but also provides other functionality. Hence it is not a pure factory object. On the other hand, the home interface itself does not depend on create() for the implementation of the other methods so that would speak against the factory method again. So it's possible to argue for both of the alternatives.

Luckily I did not encounter such difficult questions on the exam. In those questions 5 alternatives were mentioned of which 4 were absolute nonsense so that made it easier.


Ranch Hand

Joined: Aug 18, 2005
Posts: 372
I was tempted to say Factory Method at first, but on second thought, I worked out something like this :

The Abstract Factory pattern makes more sense for this scenario. I would say the home interface is the abstract factory, the home object created by the container is the concrete factory. You have one abstract product in the entire family - this is the abstract component interface. There is only one concrete product - the EJBObject created by the container implementing the component interface. The concrete factory (home object) creates the concrete product (the EJB object). The client is composed with the abstract factory (home interface) and with the abstract product (component interface), gets a concrete factory at run-time (by doing a JNDI look-up) and delegates the create call to the composed factory object (home.create()). If you think about it, it perfectly fits the AF class diagram right?
I agree. Here's the link:
subject: EJB Home uses Abstract factory or Factory Method?
It's not a secret anymore!