public class Config {
static Dictionary<int, IHandler handler> dictionary = new Dictionary<int, IHandler>() {
{ 0, new Handler() },
{ 1, new Handler() },
{ 2, new SecondHandler() }
};
public static IHandler Get(int id) { return dictionary[id].handler; }
}
interface IHandler {
void Execute(SqlConnection sqlConnection, SqlTransaction transaction, List data);
}
class Handler : IHandler {
public void Execute(SqlConnection sqlConnection, SqlTransaction transaction, List data) {
...
}
}
interface IHandlerSecond {
void Execute(SqlConnection sqlConnection, IConnection connection, SqlTransaction transaction, List data);
}
class SecondHandler : Handler, IHandlerSecond {
public void Execute(SqlConnection sqlConnection, IConnection connection, SqlTransaction transaction, List data) {
base.Execute(sqlConnection, connection, transaction);
...
}
}
void Main(IConnect connect) {
// Some code
var handler = Config.Get(num);
if(handler is IHandlerSecond) {
(handler as IHandlerSecond).Execute(connect, iconnection, transaction, data);
}
else if (handler is IHandler) {
(handler as IHandler).Execute(connect, transaction, data);
}
}
So base signature looks like
void Execute(SqlConnection sqlConnection, SqlTransaction transaction, List data);
but one handler accepts one more parameter and I trying to find best way to do this.
My best idea was to just make another interface and check for type in main function, but it’s looks kinda messy