Skip to content

Instantly share code, notes, and snippets.

@FagnerMartinsBrack
Last active November 4, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FagnerMartinsBrack/afa08cffb16a5589db06 to your computer and use it in GitHub Desktop.
Save FagnerMartinsBrack/afa08cffb16a5589db06 to your computer and use it in GitHub Desktop.
Notification OO Design Draft
public static void main( String[] args ) {
NotificationService service = new NotificationService();
// Imprime todas as notificações no view
service.listNotifications();
}
public class Notification {
Object conteudo();
Data data();
Lido lido();
}
public class NotificationFactory {
Object createConteudo();
Data createData();
Lido createLido();
}
public class NotificationService {
List<NotificacaoValue> notificacoesDoBanco = new ArrayList<>();
public List<Notification> listNotifications() {
List<Notification> result = new ArrayList<>();
for ( NotificacaoValue notificacao : notificacoesDoBanco ) {
NotificacaoFactory factory = null;
if ( notificacao.getTipo().equals( "EMAIL" ) ) {
factory = new NotificacaoEmailFactory();
}
// Constrói o resto das notificações de acordo com o tipo,
// cada factory vai construir as propriedades de uma forma diferente
result.add( new Notification( factory ) );
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment