13
from: domain-driven-design to: domain-specific language --An Example . phillip calçado http://fragmental.tw http://www.thoughtworks.com

From Domain-Driven Design to Domain-Specific Languages: an example

Embed Size (px)

DESCRIPTION

http://fragmental.tw/2008/03/24/using-the-right-words/

Citation preview

Page 1: From Domain-Driven Design to Domain-Specific Languages: an example

from: domain-driven-designto: domain-specific language--An Example.

phillip calçadohttp://fragmental.twhttp://www.thoughtworks.com

Page 2: From Domain-Driven Design to Domain-Specific Languages: an example

JavaMail Usage

Page 3: From Domain-Driven Design to Domain-Specific Languages: an example

I want this CSV report delivered

as an e-mailattachment

Page 4: From Domain-Driven Design to Domain-Specific Languages: an example

ClassicExample

Page 5: From Domain-Driven Design to Domain-Specific Languages: an example

public class Mail {

public void sendEmailWithCsvFile(String from, String to, String subject, String body, List<String> csvFileLines) {

Properties props = new Properties(); props.put("mail.smtp.host", "localhost");

Session session = Session.getDefaultInstance(props);

MimeMessage msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject(subject); msg.setSentDate(new Date());

MimeBodyPart part1 = new MimeBodyPart(); part1.setText(body);

MimeBodyPart part2 = new MimeBodyPart(); StringBuffer buffer = new StringBuffer(); for (String line : csvFileLines) buffer.append(line + "\n"); part2.setContent(buffer.toString(), "text/csv"); part2.setFileName("file.csv");

Multipart mp = new MimeMultipart(); mp.addBodyPart(part1); mp.addBodyPart(part2);

msg.setContent(mp);

Transport.send(msg); }}

Page 6: From Domain-Driven Design to Domain-Specific Languages: an example

RemovingsomeNoise

Page 7: From Domain-Driven Design to Domain-Specific Languages: an example

public class Mail {

public void sendEmailWithCsvFile(String from, String to, String subject, String body, List<String> csvFileLines) {

Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); MailService mailService = new MailService(props); MailMessage message = mailService.newMessage(); message.setFrom(from); message.setTo(to); message.setSubject(subject); message.setBody(body);

StringBuffer buffer = new StringBuffer(); for (String line : csvFileLines) buffer.append(line + "\n"); Attachment csvFile = new Attachment("file.csv", buffer.toString()); message.attach(csvFile);

mailService.send(message); }}

Page 8: From Domain-Driven Design to Domain-Specific Languages: an example

MakingitFlow

Page 9: From Domain-Driven Design to Domain-Specific Languages: an example

public class Mail {

public void sendEmailWithCsvFile(String from, String to, String subject, String body, List<String> csvFileLines) {

StringBuffer buffer = new StringBuffer(); for (String line : csvFileLines) buffer.append(line + "\n"); Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); MailService mailService = new MailService(props); mailService.newMessage() .from(from) .to(to) .subject(subject) .body(body) .attachTextFile("file3.csv", buffer.toString()) .send(); }}

Page 10: From Domain-Driven Design to Domain-Specific Languages: an example

SpeakingtheLanguage

Page 11: From Domain-Driven Design to Domain-Specific Languages: an example

send_message do to '[email protected]' from '[email protected]' subject 'Testing via JRuby'

body %{ Hi, Please do not forget the milk. Bye! }

attach('file4.csv') { ['Sk. Milk', '$1.33'] ['Avocado', '$3.00'] }end

Page 12: From Domain-Driven Design to Domain-Specific Languages: an example

Thanks