1-static factory - Effective Java 3rd version [学习笔记]

static factory 优点:

  1. have meaningful name;
  2. not required to create new object each time
    -- Singleton;
    -- Cache object;
    -- Return object based on parameters;
  3. return sub-class, not current class;
  4. returned object can vary from call to call, release to release;

缺点:
难找.

可以用 .from, .of, .valueOf, .instance, .getInstance, .create, .newInstance, .getType, .type, .newType.

标签: none

添加新评论