Design Patterns in the Light of Lambda Expressions by Subramaniam

Devoxx · 130K views · 2015 · 1:00:32

Open on YouTube

Software architecture & designFunctional programmingProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining Java 8 idioms like execute-around-method for resource handling, fluent lambda APIs, and method reference examples taken from the talk.

Recommended by 2 people across 2 different months, 2015 to 2019.

What it is

A one-hour Devoxx 2015 conference talk by Venkat Subramaniam on how Java 8 lambda expressions change the way classic design patterns are written and which new patterns become practical. It walks through examples such as execute-around-method and fluent builder-style APIs using lambdas.

What people said

Strong rec miskender · 2018-02 · Stack Overflow · on “Why are some some resources in Java not garbage collected and must be closed or autoclosed?”

If you are developing a common module(or a common util class), you can use execute around method pattern to handle resources that needs to be closed. So this way users of your module don't have handle these resource's closing.(Probably prevents many bugs, because people may forget to close the resource.) There is a great presentation by Mr Venkat, that he talks about this problem. Watch the next 10 minute, he explains this beautifully. [this video] Here is the sample code from the presentation; public class Resource { /* * This represents a resource that needs to be closed. * Since opening and closing the resource are done through use() method, * Users of this resource don't have to care about re

Recommends Kraizee · 2019-08 · Stack Overflow · on “How to define an order for a fluent lambda passed to a method”

In this talk by venkat subramaniam [this video] he makes the following Mailer example: class Mailer { public Mailer from(String addr) { System.out.println("from"); return this; } public Mailer to(String addr) { System.out.println("to"); return this; } public Mailer subject(String subjectLine) { System.out.println("subject"); return this; } public Mailer body(String message) { System.out.println("body"); return this; } public static void send(Consumer<Mailer> block) { Mailer mailer = new Mailer(); block.accept(mailer); System.out.println("sending..."); } } public class Sample { public static void main(String[] args) { Mailer.send(mailer -> { mailer.from("builder@agiledeveloper.com") .to("venkats@a

Cites Didier L · 2015-11 · Stack Overflow · on “Is there a cleaner way to use try-with-resource and PreparedStatement?”

Extending from @Tunaki's answer, it's also possible to factor-in the try-with-resources and rs.executeQuery() such that the DatabaseManager handles all of this for you and only asks for the SQL, a PreparedStatementSetter and a ResultSet handler. This would avoid repeating this everywhere you make a query. Actual API will depend on your usage however – e.g. will you make several queries with the same connection? Supposing you will, I propose the following: public class DatabaseManager implements AutoCloseable { /* Use local file for database */ private static final String JDBC_CONNECTION = "jdbc:h2:file:./db/sandbox_h2.db;MODE=PostgreSQL"; static { try { Class.forName("org.h2.Driver"); // Ini

Cites subhash kumar singh · 2017-04 · Stack Overflow · on “Error Incompatible types: Not able to understand Function<R,T> in the java8”

In the following sample code, I am not able to understand why it is complaining incompatible types: invalid method reference for case II but not for the case I . Though java.awt.Color::brighter and NewBrightColor::brightColor have similar method signature. public static void main(String[] args) { // CASE I Function<Color, Color> brighter = Color::brighter; // CASE II Function<Color, Color> newBrighter = NewBrightColor::brightColor; } class NewBrightColor { public Color brightColor() { // return some Bright color } } Edit: I have taken this example from the presentation [this video] As per my understanding, Function<R,T> should take only those function where input is R and output is T . But in cas