Contenu connexe Similaire à Domain Specific Languages (EclipseCon 2012) (20) Plus de Sven Efftinge (20) Domain Specific Languages (EclipseCon 2012)2. DOMAIN-SPECIFIC
LANGUAGE
A Domain Specific Language (DSL) is
a computer programming language
focused on a particular domain.
3. DOMAIN-SPECIFIC
LANGUAGE
Or just a hip term for a very
readable and expressive
programming interface
(aka API)
4. IT IS NOT! A WAY TO LET
BUSINESS PEOPLE WRITE SOFTWARE
5. ABSTRACTION
"THE ABILITY TO SIMPLIFY MEANS
TO ELIMINATE THE UNNECESSARY
SO THAT THE NECESSARY MAY SPEAK"
(HANS HOFMANN)
10. A TYPICAL WEB APPLICATION
Http Routing Controller Domain Model
11. A TYPICAL WEB APPLICATION
Http Routing Controller Domain Model
Data Access
12. A TYPICAL WEB APPLICATION
Http Routing Controller Domain Model
Templates for HTML, CSS and JS Data Access
13. A TYPICAL WEB APPLICATION
?
Http Routing
?
Controller ?
Domain Model
?
Templates for HTML, CSS and JS
?
Data Access
23. A TYPICAL WEB APPLICATION
Http Routing
?
Controller ?
Domain Model
?
Templates for HTML, CSS and JS
?
Data Access
26. A TYPICAL WEB APPLICATION
Http Routing Controller ?
Domain Model
?
Templates for HTML, CSS and JS
?
Data Access
29. <%@ 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>
...
30. 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)
]
]
]
31. A TYPICAL WEB APPLICATION
Http Routing Controller ?
Domain Model
Templates for HTML, CSS and JS
?
Data Access
34. .NET LINQ
val namesWithFiveCharacters = from name in names
where name.Length < 5
select name;
36. A TYPICAL WEB APPLICATION
Http Routing Controller ?
Domain Model
Templates for HTML, CSS and JS Data Access
39. @Entity
public 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;
}
}
40. ABSTRACTION
"THE ABILITY TO SIMPLIFY MEANS
TO ELIMINATE THE UNNECESSARY
SO THAT THE NECESSARY MAY SPEAK"
(HANS HOFMANN)
41. @Entity
public 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;
}
}
42. entity Customer {
id Long id
String name
Address address
onetomany Collection<Order> orders
manytomany Set<PhoneNumber> phones
}
45. 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
Notes de l'éditeur \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