Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Completely Arbitary C# Question

Say you have an object which, for the sake of example, we will call the ScoreHotChicksEngine. And say that the ScoreHotChicksEngine's constructor is expecting to be passed an IDataReader containing property values pertaining to, apparantly, Scoring Hot Chicks for Lonely Geeks.

ScoreChicksEngine(IDataReader reader);

Ok, here's what I would like to gather input on...

As a developer would you find it more useful to assume that the reader must be read before being passed into the ScoreChicksEngine

IDataReader = command.ExecuteReader();
reader.Read();
ScoreChicksEngine SCE = new ScoreChicksEngine(reader);

or would you assume that the engine itself would call that function and possibly deal with the empty values?

IDataReader  = command.ExecuteReader();
ScoreChicksEngine SCE = new ScoreChicksEngine(reader);
if (SCE.HasReaderData()) doSomething();
like image 663
Peter Lange Avatar asked May 24 '26 23:05

Peter Lange


2 Answers

Shouldn't you be thinking of decoupling the data collection from the algorithm and use a bridging solution in between (an iterator adapter, say)? Just my $0.02.

The implication of such a design is that the algorithm is responsible for making calls to read the data on an as-required basis via the adapter. The adapter hides the collection and any particular facets thereof not germane to the problem being solved.

like image 145
dirkgently Avatar answered May 27 '26 13:05

dirkgently


I'd choose the first method. The second method violates single responsibility principle. I'd also declare the input parameter of the constructor as IDataRecord and not IDataReader. Basically the SCE class constructs itself based on a single record and doesn't care about a set of records out there.

like image 20
mmx Avatar answered May 27 '26 13:05

mmx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!