HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Loose coupling, accessing class properties

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
propertiescouplinglooseclassaccessing

Problem

I'm trying to get a better understanding of decoupling methods. Right now, I have this method:

private bool ContainsLegalFirstName(DataRow row, string legalFirstNameColumn)
{
    return row.Table.Columns.Contains(legalFirstNameColumn)
        && !String.IsNullOrEmpty(row[legalFirstNameColumn].ToString());
}


I was thinking about changing the DataRow to an IDataRecord and adding an IListSource parameter and passing in the DataTable, but then the problem is I can't access the columns of the DataTable from the IListSource. Any suggestions or is what I have good enough?

Solution

As DataRow does not implement IDataRecord, you would have to pass an adapter that wraps the row and implements the interface. Also, passing an IListSource would only help if it always returned a ITypedList (which is not guaranteed) which you could then query for available properties by name. But what would be the advantage of all that?

In my opinion, the parameter types are alright. We are still talking about a private helper method, not one that needs to be accessible using all kinds of interfaces. There are, however, some things that I might change:

-

  • Either: Rename the method to represent that it actually does not care about the legal first name. You could currently rename it to ContainsLegalLastName without any change in behaviour.



  • Or: Remove the legalFirstNameColumn and get that value from somewhere else (some configuration, const, …).



  • Unless you decide to remove the column name parameter and get the column name from an instance variable, make the method static. It currently does not use any state at all.

Context

StackExchange Code Review Q#56225, answer score: 2

Revisions (0)

No revisions yet.