命名工厂功能 [英] Naming factory functions

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

问题描述

人们称他们的工厂功能为何? ''new''不是一个选项

(是的,它可以重载但必须返回void *)。


上下文是:


class MyClass

{

public:

//工厂功能

static MyClass * new(int);


//生成类的副本

虚拟MyClass * dup()= 0;


//访问函数

virtual int whatever(int)= 0;

};


对我来说最有意义的是:


MyClass * mp = MyClass :: new(1);


但是''new ''是不允许的。


工厂功能是否有准标准名称?无论什么

这个名字都不应该重复已知的信息

(MyClass :: newMyClass()很傻)。 制作副本函数,dup(),

被合理地命名(好吧,我喜欢短名字)。


我想要一个单词,暗示返回的是一个指向一个新的

版本的类(''make''和''create''并不意味着对我来说)......


Chris C

解决方案

* Chris Croughton:


我想要一个暗示什么是return是一个指向类的新
[实例]的指针(''make''和''create''并不意味着对我来说)......




如果你想要一个结果的描述,那么一个动词不好,除非

结果是一个动作。


尝试''instance''或''instanceFrom''。


这些都是好名字,似乎正是你想要的。

-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的是什么?


Chris Croughton写道:

人们称他们的工厂功能是什么? ''new''不是一个选项
(是的,它可以重载但必须返回void *)。
我想要一个单词,暗示返回的是指向该类新版本的指针(''make''和''create''并不意味着对我来说)。 ..




make_new?


2005年3月24日星期四13:35:53 GMT,Alf P 。斯坦巴赫

< al *** @ start.no>写道:

* Chris Croughton:


我想要一个单词,暗示返回的是指向新的指针
班级的[实例](''make''和''create''并不意味着对我来说)......
如果你想要对结果进行描述那么动词就不好了,除非
结果是一个动作。




方法或函数是动词,它是做事。结果是

成为事物。

尝试''instance''或''instanceFrom''。


''instanceFrom()''对我来说没什么意义。 ''newInstance()''可能

工作,但是...

这些都是好名字,似乎正是你正在寻找的东西。




''instanciate()''将是另一个,如果我使用长名称,则使用''复制()''

。我想如果我正在使用''dup()''那么我可以使用

''inst()''作为缩写。


MyClass * p = Myclass :: inst();

MyClass * q = p-> dup();


谢谢,我用完了词库中的单词...


Chris C


What do people call their factory functions? ''new'' is not an option
(yes, it can be overloaded but has to return void*).

The context is:

class MyClass
{
public:
// Factory functions
static MyClass* new(int);

// Produce a copy of the class
virtual MyClass* dup() = 0;

// Access functions
virtual int whatever(int) = 0;
};

To me it makes most sense to say:

MyClass* mp = MyClass::new(1);

but ''new'' isn''t allowed.

Are there any quasi-standard names for the factory functions? Whatever
the name it shouldn''t repeat information which is already known
(MyClass::newMyClass() is silly). The "make a copy" function, dup(),
is reasonably named (OK, I like short names).

I want a word which implies that what is returned is a pointer to a new
version of the class (''make'' and ''create'' don''t imply that to me)...

Chris C

解决方案

* Chris Croughton:


I want a word which implies that what is returned is a pointer to a new
[instance] of the class (''make'' and ''create'' don''t imply that to me)...



If you want a description of the result then a verb isn''t good, unless the
result is an action.

Try ''instance'' or ''instanceFrom''.

Those are good names and seem to be just what you''re looking for.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Chris Croughton wrote:

What do people call their factory functions? ''new'' is not an option
(yes, it can be overloaded but has to return void*). I want a word which implies that what is returned is a pointer to a new
version of the class (''make'' and ''create'' don''t imply that to me)...



make_new?


On Thu, 24 Mar 2005 13:35:53 GMT, Alf P. Steinbach
<al***@start.no> wrote:

* Chris Croughton:


I want a word which implies that what is returned is a pointer to a new
[instance] of the class (''make'' and ''create'' don''t imply that to me)...
If you want a description of the result then a verb isn''t good, unless the
result is an action.



A method or function is a verb, it''s a "doing thing". The result is a
"being thing".
Try ''instance'' or ''instanceFrom''.
''instanceFrom()'' doesn''t make much sense to me. ''newInstance()'' might
work, though...
Those are good names and seem to be just what you''re looking for.



''instanciate()'' would be another one, to go with ''duplicate()'' if I were
using long names. I suppose if I''m using ''dup()'' then I could use
''inst()'' as an abbreviation.

MyClass* p = Myclass::inst();
MyClass* q = p->dup();

Thanks, I was running out of words in the thesaurus...

Chris C


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

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