1. DSL com Rhi
no
(var Rules = {
'Descontar cliente vip' :
function() {
Café $(lista).each(
Com Pedido.descontar
Fortaleza, CE );
Tapioca 15 Março, 2008
}
})
2. Once upon a time...
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangr com
t /w t .
3. O que é um a DSL?
Linguagem específica de um
determinado domínio
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
4. O que é um a DSL?
XSLT eXtensible Stylesheet
Language Transformations
Turing Completa
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
5. O que é um a DSL?
Structured Query Language
Armazenamento de dados
Algoritmos de busca e ordenamento
Controle de concorrência DML e DDL
Transações
SELECT * FROM TABLE
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
6. O que é um a DSL?
Internal vs External
DSL Interna está DSL Externa
limitada à linguagem necessita de uma
que a hospeda e não infraestrutura de
necessita de gramática e parser de
ferramente especial sintaxe
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
7. O que é um a DSL?
Internal DSL
new EmailMessage()
.from(quot;cmilfont@gmail.comquot;)
.to(quot;cmilfont@tuangr.comquot;)
Fluent Interface .withSubject(quot;Fluent Mail APIquot;)
.withBody(quot;Demo messagequot;)
.send();
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
8. O que é um a DSL?
External DSL
String DSL = “var palestrantes =
[membros_cejug[i] for (i in
membros_cejug) if
Embedded Interpretation
(membros_cejug[i].nome ===
(Java Scripting API)
'christiano milfont')]”;
engine.eval(DSL);
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
9. Porque usar um a DSL?
Complexidade nas
operações
Mudanças frequentes
Agilidade entre a
definição e execução
Muitos pontos de
manutenção
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
10. Porque usar um a DSL?
Qual o problema?
Eu uso Strategy
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
11. Porque usar um a DSL?
public interface MessageStrategy {
public void sendMessage();
}
public abstract class AbstractStrategyFactory {
Eu que fiz!
public abstract MessageStrategy createStrategy(MessageBody mb);
}
public class MessageBody {
Object payload;
public Object getPayload() { return payload; }
public void configure(Object obj) { payload = obj; }
public void send(MessageStrategy ms) { ms.sendMessage();}
}
public class DefaultFactory extends AbstractStrategyFactory {
private DefaultFactory() {}
static DefaultFactory instance;
public static AbstractStrategyFactory getInstance() {
if (null==instance) instance = new DefaultFactory();
return instance;
}
public MessageStrategy createStrategy(final MessageBody mb) {
return new MessageStrategy() {
MessageBody body = mb;
public void sendMessage() {
Object obj = body.getPayload(); System.out.println(obj.toString());
}
};
}
}
public class HelloWorld {
public static void main(String[] args) {
MessageBody mb = new MessageBody();
mb.configure(quot;Hello World!quot;);
AbstractStrategyFactory asf = DefaultFactory.getInstance();
MessageStrategy strategy = asf.createStrategy(mb);
mb.send(strategy);
} Chri i
stano M if
lont
}
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
12. Porque usar um a DSL?
Não justifica outra
linguagem!
Faço tudo com
java!
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
13. Porque usar um a DSL?
Domain Driven Design
“Ubiquitous
language”
“Linguagem
Onipresente”
A language structured
around the domain model
and used by all team
members to connect all
the activities of the team Chri i
stano M if
lont
with the software Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
14. Porque usar um a DSL?
Rules Engine
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
15. Porque usar um a DSL?
DSL com Rhino
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
16. Porque usar um a DSL?
DSL com Rhino
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
17. Porque usar um a DSL?
DSL com Rhino
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
18. Porque usar um a DSL?
DSL com Rhino
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
19. Porque usar um a DSL?
DSL com Rhino
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
20. Porque usar um a DSL?
DSL com Rhino
Escopo definido
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
21. Porque usar um a DSL?
DSL com Rhino
Flexibilidade
Analistas de
negócios
criam regras
Agilidade nas
mudanças
Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangrcom
t /w t .
22. Chri i
stano M if
lont
Tuangr Syst s A nal
em yst
ht p:/ w w .uangr com
t /w t .
cm if @ gm ai.
lont lcom
cm if @ t
lont uangr com
.
cm if @ m if .
lont lontorg
ht p:/ w w . if .
t /w m lontorg