Alex Rivera | Logout

What are static factory methods?

Asked 2009-05-30T04:46:16.393
316

What's a "static factory" method?

Edit
Report

1 Answer

23
  • have names, unlike constructors, which can clarify code.
  • do not need to create a new object upon each invocation - objects can be cached and reused, if necessary.
  • can return a subtype of their return type - in particular, can return an object whose implementation class is unknown to the caller. This is a very valuable and widely used feature in many frameworks which use interfaces as the return type of static factory methods.

fromhttp://www.javapractices.com/topic/TopicAction.do?Id=21

answered 2009-05-30T04:52:37.977

Your Answer