patterncsharpMinor
Loose coupling, accessing class properties
Viewed 0 times
propertiescouplinglooseclassaccessing
Problem
I'm trying to get a better understanding of decoupling methods. Right now, I have this method:
I was thinking about changing the
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
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:
-
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
ContainsLegalLastNamewithout any change in behaviour.
- Or: Remove the
legalFirstNameColumnand 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.