File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Settling out which factory pattern EJBHome uses

 
Piotr Uryga
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mat Williams
Ranch Hand
Posts: 215
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for answer
Waiting for more opinions
 
Ricardo Ferreira
Ranch Hand
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic