Im trying to write the results from a SProc to a textfile. I have 3 scenarios:
SProc takes no parameters.
SProc takes parameters.
SProc takes parameters and there is a loop which increments the parameters.
scenario 1 and 2's data will be stored in a list since they are most likely to be just a single row of results.
scenario 3's data will be stored in a data table.
I was thinking of using the factory pattern for this, 3 different classes each implementing a specific interface, and a factory to determine which of the 3 would be required.
The issue is once the method is finished and the completion event has been risen, i need to know what scenario was implemented (datatable vs List) Is this an issue? If so, could someone please explain why + a possible solution?
Note: Just to clarify, this is not a plea of, please write my program.
Thanks very much for your time, i appreciate it.
Whenever you need to know an actual type behind an interface, you might have chosen a wrong point to introduce the interface. This is what it looks like here.
It looks to me like you want to separate the concern for doing your logic (which produces some data) from the logic of logging the results (in this case to a text file, but there might be other targets, right?). Why not introduce an interface for ResultLogging?
interface IResultLogger
{
void LogList(List<Something> data);
void LogDataTable(DataTable data);
}
and pass an instance of this interface to all your methods doing the logic?
If you don't want to have the "logging" (calling the IResultLogger interface) inside these methods, you might add another abstraction: The concept of "ResultData".
abstract class ResultData
{
abstract public void LogToResultLogger();
//add methods to access the data in a way you might need for other things in your program
}
and derive a "ListResultData" and "DataTableResultData".
I don't see the value of the factory pattern here.
Another way of doing it would be to have a
class ListLogger
{
public void LogList(List<Something> data) {}
}
and
class DataTableLogger
{
public void LogDataTable(DataTable data) {}
}
and do
void method1() and method2()
{
//do logic
new ListLogger().LogList(data);
}
void method3()
{
//do logic
new DataTableLogger().LogDataTable(data);
}