views:

235

answers:

12

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.

A: 

ColumnReader?

abatishchev
A: 

How is this different from doing:

myrow.Select(col => col.Col2);

?

jonnii
+2  A: 

RowReader?

Code would look like (some variations of the Get naming)

var reader = new RowReader(sourceRow);

//var value = reader.GetValue(col => col.Col2);
//var value = reader.ByColumn(col => col.Col2);
//var value = reader.ReadColumn (col => col.Col2);

Based on info by others, perhaps: RowColumnsReader. In which case the method would be Read.

eglasius
My first suggestion as well. But thinking about it, it doesn't tell you whether you're reading Rows by asking about Columns, or reading Columns by asking about Rows. Deeply ambiguous. (See "ColumnReader")
Chris B.
Added sample code, with some variations of the Get/Read, specially the latter 2 make it explicit that it is a column.
eglasius
Anything containing 'Read' or 'Write' in a function name will suggest a streaming operation.
Trap
Likewise, having Reader in the class name suggests a Stream.
Trap
well, call it coincidence, but check the Nathan's update ... I would say it plays well with that :)
eglasius
A: 

What about:

ColumnDataFetcher

EDITED

after: abatishchev comments. Thank you abatishchev.

OscarRyz
+1  A: 

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:

  • Certain attributes/data (member data)
  • Certain behaviour (member methods).

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.

LeopardSkinPillBoxHat
@Leo...: Yours belongs to the "comments" rather than "answers" no downvoting anyway.
OscarRyz
@Oscar - Why does it belong in the comments? Isn't it valid to give an answer proposing an alternative solution?
LeopardSkinPillBoxHat
A: 

RowRenderer

Pooria
A: 

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 (the ID, I guess in your case) and the methods on that object should be returning the values. Call the Row 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). The Row needs the class, not the function.

Chris B.
I agree (see my answer).
LeopardSkinPillBoxHat
A: 

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.

Boden
+1  A: 

ColumnSpaceShipRowReader

If you are storing space ships.

Flinkman
For more such ideas - http://www.classnamer.com/
Chetan Sastry
A: 

I prefer valueAt over getValue:

myrow. valueAt( col => col.Col2 );

Also, it could be nice and meaningful to have the [] operator overloaded:

var x = myRow["name"];
var x = myRow[ col => col.Col2 ];
Trap
+1  A: 

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?

data = row.read(columnName);

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.

Paul.

Paul W Homer
+1  A: 

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 :-)

paxdiablo