你会给这个物体起什么名字?
所以我有一个像这样的表:
=========================
ID | Col2 | col3 | col4 |
=========================
-> 21 | balh | blah | foo |
22 | balh | blah | foo |
我正在创建一个对象,可以使用表达式中的列名从一行读取数据。 像这样的事情:
myrow.getValue(col => col.Col2)
我目前遇到的问题是命名该对象,我无法真正找到一个描述它的功能而又不很长的名称。
你会怎么称呼它?
编辑 好的,我将添加更多详细信息,我正在使用一个 COM 对象,它一次只能读取一列。 所以我正在编写一个包装器,它可以使用 ID 从表(COM 对象内部)获取行,然后让用户使用表达式提供列名(细节并不重要)。 该对象转到表并使用 ID 和列名称获取该行的数据。
So I have a table like so:
=========================
ID | Col2 | col3 | col4 |
=========================
-> 21 | balh | blah | foo |
22 | balh | blah | foo |
I am making a object that can read the data from one row using the column name in an expression. Something like this:
myrow.getValue(col => col.Col2)
The problem I am having is at the moment is naming the object, I can't really find a name that describes what it does without being really long.
What would you call it?
EDIT Ok I'll add a few more details, I am working with a COM object which will only let me read one column at a time. So I am writing a wrapper which can fetch a row from a table(inside the COM object) using the ID, then let the user supply a column name using expression(details not important). The object goes off to the table and get the data for that row using the ID and column name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
怎么样:
ColumnDataFetcher
EDITED
之后:abatishchev 评论。 谢谢阿巴季舍夫。
What about:
ColumnDataFetcher
EDITED
after: abatishchev comments. Thank you abatishchev.
我更喜欢
valueAt
而不是getValue
:此外,重载
[]
运算符可能会很好而且很有意义:I prefer
valueAt
overgetValue
:Also, it could be nice and meaningful to have the
[]
operator overloaded:行阅读器?
代码看起来像(Get 命名的一些变体)
基于其他人的信息,可能是:RowColumnsReader。 在这种情况下,该方法将为 Read。
RowReader?
Code would look like (some variations of the Get naming)
Based on info by others, perhaps: RowColumnsReader. In which case the method would be Read.
这是对象的方法而不是对象本身,但我个人的选择是 myRow.ReadRowByCol(...) ,因为它捕获了意图。 但我也喜欢保罗的“鲍勃”:-)
That's a method of an object rather than an object itself, but my personal choice would be
myRow.ReadRowByCol(...)
since that captures the intent. But I like Paul's "Bob" as well :-)ColumnSpaceShipRowReader
如果您正在存储太空飞船。
ColumnSpaceShipRowReader
If you are storing space ships.
我会退后一步问:为什么要创建一个专门用于从列中读取值的新对象?
在我看来,最好创建一个新的方法< /em> (例如 readColumn())在封装表本身的类中。
这将是更好的面向对象实践。
类对对象进行建模,该对象具有:
在您的特定情况下,表是数据,读取是对该数据执行的行为。
因此,读取方法应该作为现有数据类中的方法来实现。
如果您创建另一个类来读取数据,您可能需要打开存储数据的类(例如,通过使用 C++ 中的友元类)。 这违反了类的封装,因为您突然允许外部类自由访问您的数据,尽管是以一种潜在受控的方式。
I would take this one step back and ask: Why are you creating a new object specifically for reading values from a column?
It sounds to me that it would be better to create a new method (e.g. readColumn()) in the class which is encapsulating the table itself.
This would be better OO practice.
A class models an object which has:
In your particular case, the table is the data, and reading is the behaviour that is performed on that data.
For this reason, a read method should be implemented as a method in the existing data class.
If you create another class to read the data, you will probably need to open up the class which is storing the data (e.g. by using friend classes in C++). This violates the encapsulation of the class, as you are suddenly allowing outside classes free access to your data, albeit in a potentially controlled fashion.
鲍勃? :-)
如果您创建一个使用列名从行中获取一些数据的方法,那么您想要的是方法而不是对象?
符合你的描述。 如果您比这更具体,您可以使用更能反映您的实际领域或抽象级别的名称。
一般来说,如果你能用一两句话描述你正在做什么,那么名词就是宾语,动词就是方法。
Bob? :-)
If you creating a method for getting some data from a row using a column name, then the thing you want is a method not an object?
matches your description. If you're more specific than that, you can use that names that closer reflect your actual domain or level of abstraction.
In general, if you can describe what you are doing in a sentence or two, the nouns are objects and the verbs are methods.
ColumnReader
?ColumnReader
?这与这样做有什么不同:
?
How is this different from doing:
?
行渲染器
RowRenderer
在我看来,您正在描述一种方法,而不是一个对象。
如果您的对象是表示某一行的列的值,那么我想将其称为单元格会非常节省。
It sounds to me like you're describing a method, not an object.
If your object is to represent the value of a column at a certain row, then I guess it'd be pretty save to call it a Cell.
RowReader
?按列行
?ColumnGrabber
?实际上,问题在于您应该设计
Row
对象 - 一个封装与给定行关联的数据的对象(ID
,我猜在您的情况下)并且该对象上的方法应该返回值。 将Row
对象称为“Row
”或“Case
”或“DataReference
”或任何对您有意义的名称应用。 那么这些方法就很容易命名(例如,Row.getColumn('col2')
)注意:
RowReader
,反思一下,是一个可怕的该类的名称。 它是不明确的,因为它读取的是列,而不是行。 ColumnReader 也很糟糕,原因相反(它通过读取行来读取列)。Row
需要类,而不是函数。RowReader
?RowByColumn
?ColumnGrabber
?Really, the issue is that you should be designing the
Row
object--an object that encapsulates the data associated with a given row (theID
, I guess in your case) and the methods on that object should be returning the values. Call theRow
object the "Row
" or "Case
" or "DataReference
" or whatever makes sense for your application. Then the methods are easy to name (e.g.,Row.getColumn('col2')
)Note:
RowReader
, on reflection, is a terrible name for this class. It's ambiguous, because it's reading columns, not rows.ColumnReader
is also bad, for the opposite reason (it reads columns by reading a row). TheRow
needs the class, not the function.