I have a Event hierarchy with some types of it namely WelcomeEvent, LogOffEvent, BilledEvent etc. I want to generate different kind of emails for these events. What I do is have a abstract Email class with types WelcomeEmail, LogoffEmail, BilledEmail. I have a EmailFactory inside which I have following method:
Email getEmail(Event event) {
if(event.instanceOf(WelcomeEvent))
return new WelcomeEmail(event);
if(event.instanceOf(LogOffEvent))
return new LogoffEmail(event);
if(event.instanceOf(LogOffEvent))
return new BilledEmail(event);
}
My reviewer says that instanceOf should be avoided as much as possible.
Is there a better way of doing this?
Aucun commentaire:
Enregistrer un commentaire