1. red is warning, blue is suggestion
  2. 1.use static factory instead of contractors
    1. static factory VS contractor
      1. has name , easy to understand
      2. do not need create a instance when call it
      3. can return any subclass instance
        1. for example: EnumSet
        2. client do not care which subclass will be used
        3. support future subclass
      4. reduce the verbosity of creating parameterized type instances.
      5. can not subclassed one class without public or protect contractor
      6. no differce with other static method , hard to find it
        1. common static factory name
          1. valueOf
          2. of
          3. newInstance
          4. getType
          5. newType
  3. 2.use builder when contractor has many parameters
    1. old methods
      1. many contractor method
        1. hard to read and control
      2. use setter method of javabean
        1. a JavaBean may be in an inconsistent state partway through its construction
    2. builder
      1. can check parameter
      2. can own many varargs
        1. jdk5
      3. only use it when has many parameter , else impact performance
  4. 3.private contractor or enum to implate Singleton
    1. before jdk5
      1. static final instance and private constructor
      2. static factory and private constructor
    2. jdk5
      1. public enum class{ INSTANCE ..}
        1. easy serializable
        2. avoid instance
  5. 4.enforce noninstantiability with private constructor
    1. can not be subclassed
  6. 5.avoid create unnessary instance
    1. as soon as reuse instance
    2. use static factory better than constructor, do not create new instance
    3. reuse unmutabled object
    4. to do link to defensive copying
  7. 6.Eliminate obsolete object references
    1. memory leak
      1. Disk Paging
      2. OutofMemoryError
      3. source
        1. reference expired
        2. cache not cleared
        3. register a rollback and not cancel register
      4. solution
        1. set null
        2. heap
  8. 7.avoid use finalizer
    1. can not sure it will be excuted
    2. impact performance
    3. call terminate method in finally
      1. do not forget call super.finalized()
  9. 分支主题 8