Static factory methods vs Instance (normal) constructors?

前端 未结 11 1481
醉梦人生
醉梦人生 2020-12-02 12:16

In a language where both are available, would you prefer to see an instance constructor or a static method that returns an instance?

For example, if you\'re creating

11条回答
  •  青春惊慌失措
    2020-12-02 12:57

    There's a paper from ICSE'07 that studied the usability of constructors vs. factory patterns. While I prefer factory patterns, the study showed that developers were slower in finding the correct factory method.

    http://www.cs.cmu.edu/~NatProg/papers/Ellis2007FactoryUsability.pdf

提交回复
热议问题