Factory Methods - Intro

7 September 2008

This post lists some facts about factory methods.

Factory methods are static methods that return an instance of the native class. Some examples from JDK include :
LogManager.getLogManager
Pattern.compile
Collections.unmodifiableCollection, Collections.synchronizeCollection Calendar.getInstance

Factory methods do not have names like constructors and do not need to create a new object upon each invocation. Objects can be cached and reused, if necessary. Factory methods can return a subtype of their return type. They can return an object whose implementation class is unknown to the caller. It is a very valuable and widely used feature in many frameworks which use interfaces as the return type of static factory methods.

Common names for factory methods include getInstance and valueOf.

del.icio.us:Factory Methods - Intro  digg:Factory Methods - Intro  spurl:Factory Methods - Intro  wists:Factory Methods - Intro  simpy:Factory Methods - Intro  newsvine:Factory Methods - Intro  blinklist:Factory Methods - Intro  furl:Factory Methods - Intro  reddit:Factory Methods - Intro  fark:Factory Methods - Intro  blogmarks:Factory Methods - Intro  Y!:Factory Methods - Intro  smarking:Factory Methods - Intro  magnolia:Factory Methods - Intro  segnalo:Factory Methods - Intro  gifttagging:Factory Methods - Intro

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Factory Methods - Intro

Leave a Reply