I have a question about how to replace IF with polymorphism.
I'll give you the following example:
Let's say I have the ExecucaoIndividual
and ExecucaoGeral
classes.
For this I created an interface to use the strategy pattern that looks like this:
interface IExecutor {
void Executar();
}
class ExecucaoIndividual : IExecutor {
public void Executar() {
//bla bla bla
}
}
class ExecucaoGeral : IExecutor {
public void Executar() {
//bla bla bla
}
}
So far beauty, but in the base class where I'm going to check which class I should call (individual or general), what would be the best approach for not having to use it:
IExecutor execucao;
if(determinadaCondicao)
execucao = new ExecucaoIndividual();
else
execucao = new ExecucaoFinal();
execucao.Executar();
I've seen some Factories
, Maps
, etc, but nothing that would take away my doubt. Can someone give me a light?