wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Settling out which factory pattern EJBHome uses 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 "Settling out which factory pattern EJBHome uses" Watch "Settling out which factory pattern EJBHome uses" New topic
Author

Settling out which factory pattern EJBHome uses

Piotr Uryga
Ranch Hand

Joined: May 25, 2006
Posts: 68
Hello !

I'm confused which factory pattern EJBHome uses, in some sources it's Factory Method, in the other ones it's Abstract Factory.
I thought that quick search of this forum history will settle this out (as usually) but... it's even worse now. The question goes back to javaranch twice a year and we have like 50/50 between Abstract Factory and Factory Method.
Here are links to older topics which answers this question:
http://www.coderanch.com/t/151048/java-Architect-SCEA/certification/Abstract-Factory-or-Factory-pattern
http://www.coderanch.com/t/150837/java-Architect-SCEA/certification/Design-Patterns
http://www.coderanch.com/t/154267/java-Architect-SCEA/certification/EJB-Home-uses-Abstract-factory
http://www.coderanch.com/t/153321/java-Architect-SCEA/certification/EJBHome-Factory-or-AbstractFactory
http://www.coderanch.com/t/151528/java-Architect-SCEA/certification/Factory-Method-Pattern
http://www.coderanch.com/t/151048/java-Architect-SCEA/certification/Abstract-Factory-or-Factory-pattern
http://www.coderanch.com/t/150852/java-Architect-SCEA/certification/Abstract-Factory-Pattern
http://www.coderanch.com/t/150355/java-Architect-SCEA/certification/Home-Interface-Abstract-Factory-or
http://www.coderanch.com/t/150209/java-Architect-SCEA/certification/factory-or-abstract-factory
http://www.coderanch.com/t/149928/java-Architect-SCEA/certification/desing-patterns
http://www.coderanch.com/t/149511/java-Architect-SCEA/certification/Design-patterns-EJB

Perhaps we should agree sth and put it in FAQ, cause it seems like one of the most common questions...

So first of all I think that when we have only one of these patterns as possible answer for the question we should always check this answer concerning Abstract Factory or Factory Method.

It's hared when we have to choose between Factory Method or Abstract Factory.
I've read that some of You call this issue a "religious question", thus we can't get answer, but as this forum is aimed for passing Sun Microsystems exam some of You have any info how it looks like according to Sun.

Thanks in advance for Your discussion and may the best Factory win.

[ October 29, 2006: Message edited by: Piotr Uryga ]

SCJP 1.4, SCWCD 1.4, SCBCD 5, SCEA
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
HI ya Piotr,

I think this an easy one personally.

The Abstract Factory according to the GOF book, is used to
Provide an interface for creating FAMILIES of related or dependent objects without specifying their concrete classes.


Where as the Factory Method
Define an interface for creating AN object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.


So the question I ask you is this - when you call create on a home inteface are you creating a family of related objects or are you creating one object??

Think about it this way, are you creating a concrete implementation of an interface and then to get a concrete object that does something specific do you need to call createConcreteObject which is responsible for creating a concrete object that matches to the environment you are running on?? The GOF book UML diagram shows the interface which has the CreateScrollBar and CreateWindow methods - these methods create the ScrollBar and Window that is appropriate for the environment. To me this does not match what is happening at all.

What happens is that you call create on the Home Interface and that creates ONE concrete implementation (EJBObject) regardless of what platform or server or whatever, you will not get one object created if you are running on windows and a different one if you are running on Solaris.

The Factory Method creates ONE concrete subclass, it does not provide a concrete subclass that just offers a way to create the family of objects appropriate for the platform, by forcing the developer to call createObjectX and createObjectY.

So for my money the pattern is quite obviously the Factory Method.

HTH

Mat
Piotr Uryga
Ranch Hand

Joined: May 25, 2006
Posts: 68
Thanks for answer
Waiting for more opinions
Ricardo Ferreira
Ranch Hand

Joined: Feb 13, 2006
Posts: 156
The main difference between the Factory method pattern and the Abstract Factory, is that the Abstract Factory is a factory FOR FACTORIES. If you need to create very distint factories for an specific problem, Abstract Factory can help you.

The Factory method pattern instead, is a factory for specific objects. For example:

Every J2EE application uses the concept of DAOFactory to define a central point where DAO objects are created. An generic DAOFactory could be like this:



The dao factory responsability is to create specific objects for a given problem. An example of usage this pattern could be:



Instead, the Abstract Factory pattern inttends to create a familie of related objects, which means that it is going to create a very Factory Methods (Yes, you can see an AF as a factory to Factory Methods). For example:



And here is a example of it's usage:

public void doSomeStuff() {

Factory factory = Factory.getInstance();
DAOFactory daoFactory = factory.createFactory("Oracle");
CustomerDao custDao = (CustomerDao) daoFactory.get("custDao");

}

That's it!


Ricardo Ferreira,<br /> <br />Sun Certified Enterprise Architect<br />IBM Certified SOA Solution Designer<br />IBM Certified RUP v7.0 Solution Designer<br />IBM Certified Specialist for RUP v2003
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Settling out which factory pattern EJBHome uses
 
Similar Threads
Why two interfaces that is home and component
factory and abstract factory
Exam Questions: Design Patterns used with EJB
EJB Home interface design pattern
difference between factory pattern , abstract factory pattern and command pattern