Upload
milfont-consulting
View
1.513
Download
7
Embed Size (px)
DESCRIPTION
Citation preview
Fortaleza, CE15 Março, 2008
DSL com Rhino
CaféComTapioca
(var Rules = { 'Descontar cliente vip' : function() { $(lista).each( Pedido.descontar ); }})
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Once upon a time...
Linguagem específica de um determinado domínio
O que é um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Turing Completa
XSLT eXtensible Stylesheet Language Transformations
O que é um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Armazenamento de dados
Structured Query Language
O que é um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Algoritmos de busca e ordenamentoControle de concorrênciaTransações
DML e DDL
SELECT * FROM TABLE
DSL Interna está limitada à linguagem que a hospeda e não
necessita de ferramente especial
Internal vs External
O que é um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
DSL Externa necessita de uma infraestrutura de
gramática e parser de sintaxe
Fluent Interface
Internal DSL
O que é um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
new EmailMessage() .from("[email protected]") .to("[email protected]") .withSubject("Fluent Mail API") .withBody("Demo message") .send();
Embedded Interpretation(Java Scripting API)
O que é um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
External DSL
String DSL = “var palestrantes = [membros_cejug[i] for (i in membros_cejug) if (membros_cejug[i].nome === 'christiano milfont')]”;
engine.eval(DSL);
Complexidade nas operações
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Mudanças frequentesAgilidade entre a
definição e execução
Muitos pontos de manutenção
Porque usar um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Qual o problema?Eu uso Strategy
Porque usar um a DSL?
Porque usar um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Eu que fiz!
public interface MessageStrategy { public void sendMessage();}
public abstract class AbstractStrategyFactory { 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("Hello World!"); AbstractStrategyFactory asf = DefaultFactory.getInstance(); MessageStrategy strategy = asf.createStrategy(mb); mb.send(strategy); }}
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
Não justifica outra linguagem!
Faço tudo com java!
Domain Driven Design
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
“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
with the software
Rules Engine
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com RhinoDSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com RhinoDSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Escopo definido
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Porque usar um a DSL?
DSL com RhinoDSL com Rhino
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
Flexibilidade
Analistas de negócios
criam regras
Agilidade nas mudanças
Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com
cm ilfont@ gm ail.comcm ilfont@ tuangr.com cm ilfont@ m ilfont.orghttp://w w w.m ilfont.org