Notes of “Effective Java” (Chapter 1-6)

Item 1: Consider static factory methods instead of constructors

advantage:

  1. Customized meaningful names better than constructors.
  2. Associated with class instead of creating new objects.
  3. Able to return subtypes.

For the 2nd advantage, static factory methods form the basis of Service provider Framework including service interface, provider interface, provider registration API and service access API.

Item 2: Consider a builder when faced with many constructor parameters

Compare with telescoping constructors and JavaBean Style.

Builder is set as a static inner class. Builder makes the object initialized immutable.

Read the rest of this entry »