-1

If not what are standard implementations of Factory Pattern and Abstract Factory Pattern?

Satyendra Kumar
  • 357
  • 2
  • 13
  • 1
    SessionFactory is a singleton instance which implements Factory design pattern – Ankur Singhal Sep 14 '15 at 08:11
  • Much confusion exists because of terms (Simple factory vs Factory method vs Abstract factory). A good reference with code is http://www.codeproject.com/Articles/716413/Factory-Method-Pattern-vs-Abstract-Factory-Pattern -- Factory method has a polymorphic method meaning there is a subclass that will implement the method and instantiate an instance of the object being created. Collection.iterator() is a great example of a factory method. See http://stackoverflow.com/questions/31017531/please-give-an-example-of-factory-method-pattern – Fuhrmanator Sep 16 '15 at 21:35

1 Answers1

1

A Factory design pattern is used when you want to create instances, but you have lots of information that you would need to pass into a constructor each time, so using a constructor becomes impractical.

The Factory instance holds lots of the state that will be common to all of the instances that get created, and then it's able to construct new instances by using that information.

Usually you'd have something like a .create() method on the factory, which might also take some parameters; the information in the arguments passed to .create(), and the information kept by the factory, would be used together to construct a new instance of whatever type the factory creates.

To answer your question, yes, HibernateSessionFactory uses a factory design pattern.

You could look at ThreadFactory for another example.

This post explains the differences between a factory method and an abstract factory pattern.

Community
  • 1
  • 1
chiastic-security
  • 20,430
  • 4
  • 39
  • 67