How to name factory like methods?

后端 未结 11 1893
别跟我提以往
别跟我提以往 2021-01-29 19:41

I guess that most factory-like methods start with create. But why are they called \"create\"? Why not \"make\", \"produce\", \"build\", \"generate\" or something el

11条回答
  •  无人及你
    2021-01-29 20:42

    Partly convention, partly semantics.

    Factory methods (signalled by the traditional create) should invoke appropriate constructors. If I saw buildURI, I would assume that it involved some computation, or assembly from parts (and I would not think there was a factory involved). The first thing that I thought when I saw generateURI is making something random, like a new personalized download link. They are not all the same, different words evoke different meanings; but most of them are not conventionalised.

提交回复
热议问题