Skip to content

Instantly share code, notes, and snippets.

@diedona
Last active November 16, 2019 16:12
Show Gist options
  • Save diedona/7325f7fc8e6376a04453e9c23df7bb0a to your computer and use it in GitHub Desktop.
Save diedona/7325f7fc8e6376a04453e9c23df7bb0a to your computer and use it in GitHub Desktop.
class Program
{
private static Dictionary<Comunicacao, IComunicacao > _comunicadores =
new Dictionary<Comunicacao, IComunicacao>()
{
{Comunicacao.EMAIL, new ComunicacaoPorEmail() },
{Comunicacao.SMS, new ComunicacaoPorSMS() },
{Comunicacao.SinalDeFumaca, new ComunicacaoPorSinalDeFumaca() }
};
static void Main(string[] args)
{
PersonService personService = new PersonService();
var pessoas = personService.CarregarPessoas();
foreach (var pessoa in pessoas)
{
// recupera a estratégia concreta de comunicação do dicionário
personService.DefinirEstrategia(_comunicadores[pessoa.ComunicacaoPreferida]);
personService.EnviarComunicacao(pessoa, new Mensagem("EAE", "Td bão?", false));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment