Domain Specific Languages (EclipseCon 2012)

935 views

Published on

A presentation on domain

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
935
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Domain Specific Languages (EclipseCon 2012)

    1. 1. DOMAIN-SPECIFIC LANGUAGES @svenefftinge
    2. 2. DOMAIN-SPECIFIC LANGUAGEA Domain Specific Language (DSL) is a computer programming language focused on a particular domain.
    3. 3. DOMAIN-SPECIFIC LANGUAGE Or just a hip term for a veryreadable and expressiveprogramming interface (aka API)
    4. 4. IT IS NOT! A WAY TO LETBUSINESS PEOPLE WRITE SOFTWARE
    5. 5. ABSTRACTION "THE ABILITY TO SIMPLIFY MEANS TO ELIMINATE THE UNNECESSARYSO THAT THE NECESSARY MAY SPEAK" (HANS HOFMANN)
    6. 6. A TYPICAL WEB APPLICATIONRequestResponse
    7. 7. A TYPICAL WEB APPLICATION
    8. 8. A TYPICAL WEB APPLICATIONHttp Routing
    9. 9. A TYPICAL WEB APPLICATIONHttp Routing Controller
    10. 10. A TYPICAL WEB APPLICATIONHttp Routing Controller Domain Model
    11. 11. A TYPICAL WEB APPLICATIONHttp Routing Controller Domain Model Data Access
    12. 12. A TYPICAL WEB APPLICATIONHttp Routing Controller Domain Model Templates for HTML, CSS and JS Data Access
    13. 13. A TYPICAL WEB APPLICATION ?Http Routing ? Controller ? Domain Model ? Templates for HTML, CSS and JS ? Data Access
    14. 14. Http Routing
    15. 15. HTTP-ROUTING WITH SERVLET API
    16. 16. Java / Xtend
    17. 17. HTTP-ROUTING WITH JAX-RS Java / Xtend
    18. 18. HTTP-ROUTING WITH PLAY!
    19. 19. HTTP-ROUTING WITH PLAY! Static Typing ?
    20. 20. HTTP-ROUTING WITH PLAY! Static Typing ? Viewpoint Specific Analysis?
    21. 21. A TYPICAL WEB APPLICATIONHttp Routing ? Controller ? Domain Model ? Templates for HTML, CSS and JS ? Data Access
    22. 22. Controller
    23. 23. ControllerUse a General Purpose Language: Java, ..., Xtend, ...
    24. 24. A TYPICAL WEB APPLICATIONHttp Routing Controller ? Domain Model ? Templates for HTML, CSS and JS ? Data Access
    25. 25. Templates for HTML, CSS and JS
    26. 26. <%@ page language="java" import="captchas.CaptchasDotNet" %><html>  <head>    <title>Sample JSP CAPTCHA Query</title>  </head>  <h1>Sample JSP CAPTCHA Query</h1><% CaptchasDotNet captchas = new captchas.CaptchasDotNet(  request.getSession(true),     // Ensure session  "demo",                       // client  "secret"                      // secret  );%>  <form method="get" action="<%=response.encodeUrl("check.jsp")%>">    <table>      <tr>        <td><input name="message" size="60" />        </tr>      <tr>        <td>          <input name="password" size="16" />        </td>      </tr>      <tr>        <td>          <%= captchas.image() %><br>          <a href="<%= captchas.audioUrl() %>">Phonetic spelling (mp3)</a>        </td>      </tr>      <tr>        <td>          <input type="submit" value="Submit" />        </td>      </tr>    </table>  </form></html>
    27. 27. <%@ page language="java" import="captchas.CaptchasDotNet" %><html>  <head>  </head> Java Server Pages    <title>Sample JSP CAPTCHA Query</title>  <h1>Sample JSP CAPTCHA Query</h1> Velocity<% CaptchasDotNet captchas = new captchas.CaptchasDotNet(  request.getSession(true),     // Ensure session  "demo",                       // client Freemarker  "secret"                      // secret  );%>  <form method="get" action="<%=response.encodeUrl("check.jsp")%>"> Hamlets    <table>      <tr>        <td><input name="message" size="60" /> Scalate        </tr>      <tr>        <td>          <input name="password" size="16" />        </td>      </tr>      <tr> StringTemplate        <td> Thymeleaf          <%= captchas.image() %><br>          <a href="<%= captchas.audioUrl() %>">Phonetic spelling (mp3)</a> Jamon        </td>      </tr>      <tr> WebMacro        <td>          <input type="submit" value="Submit" />        </td>      </tr>    </table>  </form></html> ...
    28. 28. html [ head [ title [$("XML encoding with Xtend")] ] body [ h1 [$("XML encoding with Xtend")] p [$("this format can be used as an alternative to XML")] // an element with attributes and text content a("http://www.xtend-lang.org") [$("Xtend")] // mixed content p [ $("This is some") b[$("mixed")] $("text. For more see the") a("http://www.xtext.org")[$("Xtext")] $("project") ] p [$("some text")] // content generated from arguments p [ for (arg : args) $(arg) ] ]]
    29. 29. A TYPICAL WEB APPLICATIONHttp Routing Controller ? Domain Model Templates for HTML, CSS and JS ? Data Access
    30. 30. Data Access
    31. 31. DATA ACCESS WITHJPA QUERY LANGUAGE
    32. 32. .NET LINQ val namesWithFiveCharacters = from name in names                                where name.Length < 5                                 select name;
    33. 33. SCALA QUERYval q1 = for(u <- Users if u.first === "Stefan") yield u.id ~ u.last
    34. 34. A TYPICAL WEB APPLICATIONHttp Routing Controller ? Domain Model Templates for HTML, CSS and JS Data Access
    35. 35. Domain Model
    36. 36. @Entitypublic class Customer implements Serializable { private Long id; private String name; private Address address; private Collection<Order> orders = new HashSet<Order>(); private Set<PhoneNumber> phones = new HashSet<PhoneNumber>(); public Customer() {} @Id public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @OneToMany public Collection<Order> getOrders() { return orders; } public void setOrders(Collection<Order> orders) { this.orders = orders; } @ManyToMany public Set<PhoneNumber> getPhones() { return phones; } public void setPhones(Set<PhoneNumber> phones) { this.phones = phones; }}
    37. 37. ABSTRACTION "THE ABILITY TO SIMPLIFY MEANS TO ELIMINATE THE UNNECESSARYSO THAT THE NECESSARY MAY SPEAK" (HANS HOFMANN)
    38. 38. @Entitypublic class Customer implements Serializable { private Long id; private String name; private Address address; private Collection<Order> orders = new HashSet<Order>(); private Set<PhoneNumber> phones = new HashSet<PhoneNumber>(); public Customer() {} @Id public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @OneToMany public Collection<Order> getOrders() { return orders; } public void setOrders(Collection<Order> orders) { this.orders = orders; } @ManyToMany public Set<PhoneNumber> getPhones() { return phones; } public void setPhones(Set<PhoneNumber> phones) { this.phones = phones; }}
    39. 39. entity Customer { id Long id String name Address address onetomany Collection<Order> orders manytomany Set<PhoneNumber> phones}
    40. 40. com.springsource.roo.pizzashop roo> entity --class ~.domain.Topping --testAutomatically~.domain.Topping roo> field string --fieldName name --notNull --sizeMin 2~.domain.Topping roo> entity --class ~.domain.Base --testAutomatically~.domain.Base roo> field string --fieldName name --notNull --sizeMin 2~.domain.Base roo> entity --class ~.domain.Pizza --testAutomatically~.domain.Pizza roo> field string --fieldName name --notNull --sizeMin 2~.domain.Pizza roo> field number --fieldName price --type java.lang.Float~.domain.Pizza roo> field set --fieldName toppings --type ~.domain.Topping~.domain.Pizza roo> field reference --fieldName base --type ~.domain.Base~.domain.Pizza roo> entity --class ~.domain.PizzaOrder --testAutomatically~.domain.PizzaOrder roo> field string --fieldName name --notNull --sizeMin 2~.domain.PizzaOrder roo> field string --fieldName address --sizeMax 30~.domain.PizzaOrder roo> field number --fieldName total --type java.lang.Float~.domain.PizzaOrder roo> field date --fieldName deliveryDate --type java.util.Date~.domain.PizzaOrder roo> field set --fieldName pizzas --type ~.domain.Pizza
    41. 41. LAYERS
    42. 42. ABSTRACTION
    43. 43. ONE SIZE FITS ALL?
    44. 44. Know your toolbox, be creative and have fun! Thank you!

    ×