In this talk we explain how we use the more recent concepts of the Java programming language in order to improve readability and maintainability of our code.
20. Java’s Syntax is Inflexible
All infix operators work for built-in types only.
21. Java’s Syntax is Inflexible
All infix operators work for built-in types only.
2 / 4 * 13;
22. Java’s Syntax is Inflexible
All infix operators work for built-in types only.
2 / 4 * 13;
new BigDecimal(2)
.divide(new BigDecimal(4))
.multiply(new BigDecimal(13));
24. Java lacks Closures
Working with collections in Java (i.e. without closures):
public List<String> fourLetterWords(List<String> words) {
List<String> fourLetterWords = Lists.newArrayList();
for (String string : words) {
if (string.length()==4)
fourLetterWords.add(string);
}
return fourLetterWords;
}
25. Java lacks Closures
Working with collections in Java (i.e. with closures):
public List<String> fourLetterWords(List<String> words) {
return words.select(#{s->s.length()==4});
}
65. Constructor Parameters
... Have Advantages
• Components Depend on Interfaces
• Testable Code
66. Constructor Parameters
... Have Advantages
• Components Depend on Interfaces
• Testable Code
• Dependencies are No Longer Burried in the
Core of Your Application
68. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
69. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
SoapConnection soap = new SoapConnection(http);
70. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
SoapConnection soap = new SoapConnection(http);
Shortener shortener = new TinyUrlShortener(soap);
71. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
SoapConnection soap = new SoapConnection(http);
Shortener shortener = new TinyUrlShortener(soap);
AndroidSmsSender sender = new AndroidSmsSender();
72. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
SoapConnection soap = new SoapConnection(http);
Shortener shortener = new TinyUrlShortener(soap);
AndroidSmsSender sender = new AndroidSmsSender();
Tweeter tweeter = new SmsTweeter(sender);
73. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
SoapConnection soap = new SoapConnection(http);
Shortener shortener = new TinyUrlShortener(soap);
AndroidSmsSender sender = new AndroidSmsSender();
Tweeter tweeter = new SmsTweeter(sender);
TwitterClient client = new TwitterClient(shortener, tweeter);
74. Constructor Parameters
... Leave the Burden to the Client
HttpConnection http = new HttpConnection(“..”);
SoapConnection soap = new SoapConnection(http);
Shortener shortener = new TinyUrlShortener(soap);
AndroidSmsSender sender = new AndroidSmsSender();
Tweeter tweeter = new SmsTweeter(sender);
TwitterClient client = new TwitterClient(shortener, tweeter);
client.send(“Hello World”);
111. Polymorphic Dispatching
• Non Invasive External Visitor
• Handle Arbitrary Object Graphs
• Eliminate if-instanceof-else Cascades
• Dispatch According to Runtime Type of Arguments
(Like switch-Statement on Types)
119. Annotation-based APIs
• More Concise Code
• Avoid Anonymous Classes
• Easier to Understand
120. Annotation-based APIs
• More Concise Code
• Avoid Anonymous Classes
• Easier to Understand
• Less Code to Maintain
121. Annotation-based APIs
• More Concise Code
• Avoid Anonymous Classes
• Easier to Understand
• Less Code to Maintain
• Method can be overwritten
(Extensibility, Testability)