22
Fortaleza, CE 15 Março, 2008 DSL com Rhino Café Com T apioca (var Rules = { 'Descontar cliente vip' : function() { $(lista).each( Pedido.descontar ); } })

Cct Dsl

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Cct Dsl

Fortaleza, CE15 Março, 2008

DSL com Rhino

CaféComTapioca

(var Rules = { 'Descontar cliente vip' : function() { $(lista).each( Pedido.descontar ); }})

Page 2: Cct Dsl

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Once upon a time...

Page 3: Cct Dsl

Linguagem específica de um determinado domínio

O que é um a DSL?

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Page 4: Cct Dsl

Turing Completa

XSLT eXtensible Stylesheet Language Transformations

O que é um a DSL?

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Page 5: Cct Dsl

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

Page 6: Cct Dsl

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

Page 7: Cct Dsl

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();

Page 8: Cct Dsl

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);

Page 9: Cct 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?

Page 10: Cct Dsl

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Qual o problema?Eu uso Strategy

Porque usar um a DSL?

Page 11: Cct 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); }}

Page 12: Cct Dsl

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!

Page 13: Cct Dsl

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

Page 14: Cct Dsl

Rules Engine

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Porque usar um a DSL?

Page 15: Cct Dsl

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Porque usar um a DSL?

DSL com Rhino

Page 16: Cct Dsl

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Porque usar um a DSL?

DSL com Rhino

Page 17: Cct Dsl

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Porque usar um a DSL?

DSL com Rhino

Page 18: Cct Dsl

Christiano M ilfontTuangr System s Analysthttp://w w w.tuangr.com

Porque usar um a DSL?

DSL com Rhino

Page 19: Cct Dsl

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

Page 20: Cct Dsl

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

Page 21: Cct Dsl

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

Page 22: Cct Dsl

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