You could move the "if" statement to a factory class
public interface IDataHandler
{
void PopulateGridView(GridView gridView);
}
public class AccountsHandler : IDataHandler
{
public void PopulateGridView(GridView gridView)
{
}
}
public class PersonsHandler : IDataHandler
{
public void PopulateGridView(GridView gridView)
{
}
}
public class DataHandlerFactory
{
public IDataHandler GetDataHandler (ListViewTypes types)
{
switch(types)
{
case ListViewTypes.Accounts:
return new AccountsHandler();
case ListViewTypes.Persons:
return new PersonsHandler();
default:
throw new NotImplementedException();
}
}
}
usage
DataHandlerFactory f = new DataHandlerFactory();
IDataHandler dh = f.GetDataHandler(types);
dh.PopulateGridView(GridView1);
You could even do something like this to get rid of the switch
public class DataHandlerFactory
{
private static Dictionary<ListViewTypes, IDataHandler> handlers;
static DataHandlerFactory()
{
handlers = new Dictionary<ListViewTypes, IDataHandler>();
handlers.Add(ListViewTypes.Accounts, new AccountsHandler());
handlers.Add(ListViewTypes.Persons, new PersonsHandler());
}
public IDataHandler GetDataHandler (ListViewTypes types)
{
IDataHandler dh;
if (!handlers.TryGetValue(types, out dh))
{
throw new NotImplementedException();
}
return dh;
}
}