• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is a factory ?

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the last message posted.

In the "EJB 2.0 Development with WebSphere Studio Application Developer", i read :
The EJB home component is comparable to a factory for the EJB objects.
What does it mean clearly ?
Thanks.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A factory is a common OO pattern. You can find some explanations at:
http://www.dofactory.com/Patterns/PatternAbstract.aspx

Hope it helps
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, if i understand good, the purpose of using a factory class is to prevent from having many instances of a class ?
The factory class will be responsible to return the same instance. Is right ? or i'm completely mistaken ?
 
Author
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Engin
This is incorrect. A factory is not used to prevent having too many instances of a class. There is a pattern that ensures that you have no more than one instance of a class--that pattern is called singleton.

A factory is used as an interface for object creation that allows subclasses to decide which object to instantiate. It is typically used when it cannot be anticipated what specific class needs to be created, or when you want to delegate responsibility of object creation to a helper.

The advantage of this is that the client code only has to deal with the interface, and not rely on some specific implementation. The design can then be more open.

A typical example of a factory is a when a container hands out datasource connections.
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly what Eben said.

You should use it when you want to hide how your object is created.
[ August 03, 2004: Message edited by: Vinicius Boson ]
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eben and Venicius thanks.
1.
I saw that the factory class created an instance of the appropriated class.
As you say, if we don't know wich database we will use, the factory will create an instance of the class wich handles the connection,drivers..with the concerned database.
Until here is right ?

2.Then can we say also the factory is like a controller then ? I say it because in MVC (Swing) i have a controller wich instantiates the appropriated class for printing my screen.
I give you here an example of my controller i have :


public class SecurityFopController extends FopController {

public SecurityFopController(int report, JComponent comp)
{
super(report, comp);
mModule = ApplicationConstants.MOD_SECURITY; // = 16

switch(report)
{
case ApplicationConstants.REP_SECURITY_CONSULTATION :
mFilename = "Consultation"; // to define the file name of the PDF with the date
mXSL = ApplicationConstants.REP_SECURITY_CONSULTATION_XSL; // to know wich XSL file to use
mXMLBuilder = new ConsultationXMLBuilder((Consultation) comp);
break;

case ApplicationConstants.REP_SECURITY_GESTION_GROUPE :
mFilename = "Gestion_des_groupes"; // to define the file name of the PDF with the date
mXSL = ApplicationConstants.REP_SECURITY_GESTION_GROUPE_XSL; // to know wich XSL file to use
mXMLBuilder = new GestionGroupXMLBuilder((GestionGroupes) comp);
break;
}
}
}
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any suggestion to my topic ?
 
I am a man of mystery. Mostly because of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic