Question:

What are Factory classes and Factory methods in java?

by  |  earlier

0 LIKES UnLike

could anybody please explain me what are called Factory Classes and Factory methods in java programming language?

Thanks in advance

 Tags:

   Report

3 ANSWERS


  1. When you first learn to develop object in Java, you use the operator called "new", along with a constructor to create an object.

    Sometimes, you want to have more control and you can make your constructor private so that it can't be called from outside of your class.  Then for a caller outside of the class, you would develop a factory method that would create an object of that class by calling the constructor from the factory method.

    In short, a "factory method" exists to control the way in which the object is created by forcing the caller to create an object using the a call to the factory method instead of by directly calling a constructor.


  2. see it in google

    it is concept of middleware

    i am not clear in concept

    but heared about it

    for combining more than one components in J2EE in home serverside

  3. The ideas are more general than Java. These are Design Patterns that can be implemented in any OO language.

    Factory is a creational Design Pattern. There is an Abstract Factory, which is a class-level pattern and a Factory Method pattern at the object level.

    Often, there are several different classes that provide related services in very different ways. A client only knows that it needs a service and only needs to know the name of the method that provides that service, not what the object implementation of the service is. The Factory pattern allows the service to decide for itself which of the various forms of object should be returned to the client to satisfy the request.

    Abstract Factory

    UML

    http://www.apwebco.com/gofpatterns/creat...

    Discussion

    http://en.wikipedia.org/wiki/Abstract_fa...

    Factory Method

    UML

    http://www.apwebco.com/gofpatterns/creat...

    Discussion

    http://en.wikipedia.org/wiki/Factory_met...

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.