c# - factory pattern, need to know the actual implementation type? -
im trying write results sproc textfile. have 3 scenarios:
sproc takes no parameters.
sproc takes parameters.
sproc takes parameters , there loop increments parameters.
scenario 1 , 2's data stored in list since single row of results.
scenario 3's data stored in data table.
i thinking of using factory pattern this, 3 different classes each implementing specific interface, , factory determine of 3 required.
the issue once method finished , completion event has been risen, need know scenario implemented (datatable vs list) issue? if so, please explain why + possible solution?
note: clarify, not plea of, please write program.
thanks time, appreciate it.
whenever need know actual type behind interface, might have chosen wrong point introduce interface. looks here.
it looks me want separate concern doing logic (which produces data) logic of logging results (in case text file, there might other targets, right?). why not introduce interface resultlogging?
interface iresultlogger { void loglist(list<something> data); void logdatatable(datatable data); } and pass instance of interface methods doing logic?
if don't want have "logging" (calling iresultlogger interface) inside these methods, might add abstraction: concept of "resultdata".
abstract class resultdata { abstract public void logtoresultlogger(); //add methods access data in way might need other things in program } and derive "listresultdata" , "datatableresultdata".
i don't see value of factory pattern here.
another way of doing have
class listlogger { public void loglist(list<something> data) {} } and
class datatablelogger { public void logdatatable(datatable data) {} } and
void method1() , method2() { //do logic new listlogger().loglist(data); } void method3() { //do logic new datatablelogger().logdatatable(data); }
Comments
Post a Comment