如何命名工厂like方法? [英] How to name factory like methods?

查看:136
本文介绍了如何命名工厂like方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想大多数工厂类似的方法从 create 开始。但为什么他们被称为创建?为什么不 make produce build a>,生成或其他内容?这只是味道的问题吗?公约?或者在创建中有特殊的含义吗?

I guess that most factory like methods start with create. But why are they called "create"? Why not "make", "produce", "build", "generate" or something else? Is it only a matter of taste? A convention? Or is there a special meaning in "create"?

createURI(...) 
makeURI(...)
produceURI(...)
buildURI(...)
generateURI(...)

$

推荐答案

一些随机的想法:


  • 创建比大多数其他字词更适合该功能。下一个最好的话,我可以想到的头顶是构造。在过去,Alloc(分配)可能在类似情况下使用,反映出比C语言中的对象更强调数据块。

  • 'Create' fits the feature better than most other words. The next best word I can think of off the top of my head is 'Construct'. In the past, 'Alloc' (allocate) might have been used in similar situations, reflecting the greater emphasis on blocks of data than objects in languages like C.

'创建'是一个简单,简单的单词,有一个明确的直觉的意义。在大多数情况下,人们可能只是选择它作为第一个,最明显的单词,当他们想创造的东西。

'Create' is a short, simple word that has a clear intuitive meaning. In most cases people probably just pick it as the first, most obvious word that comes to mind when they wish to create something. It's a common naming convention, and "object creation" is a common way of describing the process of... creating objects.

构造是接近的,它是一种常见的命名约定,对象创建是描述创建对象过程的常用方法。但它通常用于描述创建对象(分配/新建,构造,初始化...)过程中的特定阶段。

'Construct' is close, but it is usually used to describe a specific stage in the process of creating an object (allocate/new, construct, initialise...)

和Make是与编译代码相关的过程的常见术语,因此具有与程序员不同的内涵,意味着包括许多步骤和可能的很多磁盘活动的过程。然而,工厂构建某物的想法是一个明智的想法 - 尤其是在构建复杂数据结构的情况下,或者以某种方式组合了许多单独的信息。

'Build' and 'Make' are common terms for processes relating to compiling code, so have different connotations to programmers, implying a process that comprises many steps and possibly a lot of disk activity. However, the idea of a Factory "building" something is a sensible idea - especially in cases where a complex data-structure is built, or many separate pieces of information are combined in some way.

生成表示用于从输入生成值的计算,例如生成散列码或随机数。

'Generate' to me implies a calculation which is used to produce a value from an input, such as generating a hash code or a random number.

生成,生成,构造比创建更长的输入/读取。历史上,程序员喜欢短名字以减少打字/阅读。

'Produce', 'Generate', 'Construct' are longer to type/read than 'Create'. Historically programmers have favoured short names to reduce typing/reading.

这篇关于如何命名工厂like方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆