View RSS Feed

My Java Tips

  1. Factory Methods

    by , 06-02-2011 at 07:11 PM (My Java Tips)
    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 ...