官术网_书友最值得收藏!

Advantages of the Static Factory Method

Here are some of the advantages of a Static Factory Method over constructors:

  • It provides a better name for the constructor, what it expects, and, sometimes, what it produces.
  • We usually don't expect exceptions from a constructor. Exceptions from a regular method, on the other hand, are totally valid.
  • Speaking of expectations, we expect the constructor to be fast. 

But those are more psychological advantages. There are also some technological advantages to this approach.

主站蜘蛛池模板: 贵港市| 格尔木市| 余干县| 明溪县| 珠海市| 城固县| 仁怀市| 从江县| 阿图什市| 长武县| 榆社县| 巨野县| 林芝县| 罗平县| 灵川县| 普陀区| 庄河市| 邵武市| 黄龙县| 华蓥市| 辉南县| 佛学| 宣威市| 延边| 涪陵区| 金乡县| 博野县| 荥经县| 房产| 永和县| 雅安市| 汝城县| 平邑县| 施甸县| 昭通市| 同德县| 灵石县| 浦县| 盐池县| 萨迦县| 兴海县|