SlideShare a Scribd company logo
Design Patterns 
in the 21st Century 
15th October 2014 
@SamirTalwar
What do you want 
from me? 
I want you to stop using design patterns.
What do you want 
from me? 
I want you to stop using design patterns… 
like it’s 1999.
The elements of this language are entities 
called patterns. Each pattern describes a 
problem that occurs over and over again in our 
environment, and then describes the core of the 
solution to that problem, in such a way that you 
can use this solution a million times over, 
without ever doing it the same way twice. 
– Christopher Alexander
And now, an aside, on 
functional programming.
int courses = 3; 
Course dessert = 
prepareCake.madeOf(chocolate); 
Preparation prepareCake = new Preparation() { 
@Override 
public Course madeOf(Ingredient mmmmm) { 
return 
new CakeMix(eggs, butter, sugar) 
.combinedWith(mmmmm); 
} 
};
Preparation prepareCake = new Preparation() { 
@Override 
public Course madeOf(Ingredient mmmmm) { 
return 
new CakeMix(eggs, butter, sugar) 
.combinedWith(mmmmm); 
} 
}; 
Preparation prepareCake = 
mmmmm -> 
new CakeMix(eggs, butter, sugar) 
.combinedWith(mmmmm);
Preparation prepareCake = 
mmmmm -> 
new CakeMix(eggs, butter, sugar) 
.combinedWith(mmmmm); 
Mix mix = new CakeMix(eggs, butter, sugar); 
Preparation prepareCake = 
mix::combinedWith;
Mix mix = new CakeMix(eggs, butter, sugar); 
Preparation prepareCake = 
mix::combinedWith; 
Course combinedWith(Ingredient); 
@FunctionalInterface 
interface Preparation { 
Course madeOf(Ingredient mmmmm); 
}
Well.
On to the Good Stuff
The 
Abstract Factory 
pattern
public interface Bakery { 
Pastry bakePastry(Topping topping); 
Cake bakeCake(); 
} 
public class DanishBakery implements Bakery { 
@Override 
public Pastry bakePastry(Topping topping) { 
return new DanishPastry(topping); 
} 
@Override 
public Cake bakeCake() { 
return new Æblekage(); // mmmm, apple cake… 
} 
} 
Abstract Factory
public interface Bakery { 
Pastry bakePastry(Topping topping); 
} 
public class DanishBakery implements Bakery { 
@Override 
public Pastry bakePastry(Topping topping) { 
return new DanishPastry(topping); 
} 
} 
Abstract Factory
Abstract Factory 
public class DanishBakery implements Bakery { 
@Override 
public Pastry bakePastry(Topping topping) { 
return new DanishPastry(topping); 
} 
} 
Bakery danishBakery = topping -> 
new DanishPastry(topping); 
Bakery danishBakery = DanishPastry::new;
package java.util.function; 
/** 
* Represents a function that 
* accepts one argument and produces a result. 
* 
* @since 1.8 
*/ 
@FunctionalInterface 
public interface Function<T, R> { 
/** 
* Applies this function to the given 
argument. 
*/ 
R apply(T t); 
... 
} 
Abstract Factory
public class DanishBakery 
implements Function<Topping, Pastry> { 
@Override 
public Pastry apply(Topping topping) { 
return new DanishPastry(topping); 
} 
} 
Function<Topping, Pastry> danishBakery 
= topping -> 
new DanishPastry(topping); 
Function<Topping, Pastry> danishBakery 
= DanishPastry::new; 
Abstract Factory
The 
Adapter 
pattern
interface Fire { 
<T> Burnt<T> burn(T thing); 
} 
interface Oven { 
Food cook(Food food); 
} 
class WoodFire implements Fire { ... } 
class MakeshiftOven 
extends WoodFire 
implements Oven { 
@Override public Food cook(Food food) { 
Burnt<Food> nastyFood = burn(food); 
return nastyFood.scrapeOffBurntBits(); 
} 
} 
Adapter
interface Fire { 
<T> Burnt<T> burn(T thing); 
} 
interface Oven { 
Food cook(Food food); 
} 
class MakeshiftOven implements Oven { 
private final Fire fire; 
public MakeshiftOven(Fire fire) { /* ... */ } 
@Override public Food cook(Food food) { 
Burnt<Food> nastyFood = fire.burn(food); 
return nastyFood.scrapeOffBurntBits(); 
} 
} 
Adapter
interface Oven { 
Food cook(Food food); 
} 
Oven oven = new MakeshiftOven(fire); 
Food bakedPie = oven.cook(pie); 
Adapter
interface Oven { 
Food cook(Food food); 
} 
class MakeshiftOven implements Oven { 
private final Fire fire; 
public MakeshiftOven(Fire fire) { /* ... */ } 
@Override public Food cook(Food food) { 
Burnt<Food> nastyFood = fire.burn(food); 
return nastyFood.scrapeOffBurntBits(); 
} 
} 
Adapter
class MakeshiftOven implements Oven { 
private final Fire fire; 
public MakeshiftOven(Fire fire) { /* ... */ } 
@Override public Food cook(Food food) { 
Burnt<Food> nastyFood = fire.burn(food); 
return nastyFood.scrapeOffBurntBits(); 
} 
} 
Oven oven = food -> { 
Burnt<Food> nastyFood = fire.burn(food); 
return nastyFood.scrapeOffBurntBits(); 
}; 
Food bakedPie = oven.cook(pie); 
Adapter
Oven oven = food -> { 
Adapter 
Burnt<Food> nastyFood = fire.burn(food); 
return nastyFood.scrapeOffBurntBits(); 
}; 
Oven oven = food -> 
fire.burn(food).scrapeOffBurntBits();
Oven oven = food -> 
fire.burn(food).scrapeOffBurntBits(); 
// Do *not* do this. 
Function<Food, Burnt<Food>> burn 
= fire::burn; 
Function<Food, Food> cook 
= burn.andThen(Burnt::scrapeOffBurntBits); 
Oven oven = cook::apply; 
Food bakedPie = oven.cook(pie); 
Adapter
package java.util.concurrent; 
/** 
* An object that executes 
* submitted {@link Runnable} tasks. 
*/ 
public interface Executor { 
void execute(Runnable command); 
} 
Adapter
public interface Executor { 
void execute(Runnable command); 
} 
Executor executor = ...; 
Stream<Runnable> tasks = ...; 
tasks.forEach(executor); 
Adapter
public interface Stream<T> { 
... 
void forEach(Consumer<? super T> action); 
... 
} 
@FunctionalInterface 
public interface Consumer<T> { 
void accept(T t); 
... 
} 
Adapter
public interface Executor { 
void execute(Runnable command); 
} 
@FunctionalInterface 
public interface Consumer<T> { 
void accept(T t); 
} 
Executor executor = ...; 
Stream<Runnable> tasks = ...; 
tasks.forEach(task -> executor.execute(task)); 
tasks.forEach(executor::execute); 
/
executor::execute 
Adapter
The 
Chain of Responsibility 
pattern
@Test public void whoAteMyPie() { 
PieEater alice = PieEater.whoLoves(APPLE); 
PieEater bob = PieEater.whoLoves(BLUEBERRY); 
PieEater carol = PieEater.whoLoves(CHERRY); 
alice.setNext(bob); 
bob.setNext(carol); 
alice.give(blueberryPie); 
assertThat(bob, ate(blueberryPie)); 
} 
Chain of 
Responsibility
public final class HitCounterFilter implements Filter { 
private FilterConfig filterConfig = null; 
public void init(FilterConfig filterConfig) throws ServletException { 
this.filterConfig = filterConfig; 
} 
public void destroy() { 
this.filterConfig = null; 
} 
public void doFilter 
(ServletRequest request, ServletResponse response, FilterChain chain) 
throws IOException, ServletException { 
if (filterConfig == null) 
return; 
Counter counter = 
(Counter)filterConfig.getServletContext().getAttribute("hitCounter"); 
StringWriter sw = new StringWriter(); 
PrintWriter writer = new PrintWriter(sw); 
writer.println("The number of hits is: " + counter.incCounter()); 
writer.flush(); 
filterConfig.getServletContext().log(sw.getBuffer().toString()); 
chain.doFilter(request, response); 
} 
} 
Chain of 
Responsibility
public final class HitCounterFilter 
implements Filter { 
// init and destroy 
public void doFilter( 
ServletRequest request, 
ServletResponse response, 
FilterChain chain) { 
int hits = getCounter().incCounter(); 
log(“The number of hits is ” + hits); 
chain.doFilter(request, response); 
} 
} 
Chain of 
Responsibility
public final class SwitchEncodingFilter 
implements Filter { 
// init and destroy 
public void doFilter( 
ServletRequest request, 
ServletResponse response, 
FilterChain chain) { 
request.setEncoding(“UTF-8”); 
chain.doFilter(request, response); 
} 
} 
Chain of 
Responsibility
public final class AuthorizationFilter 
implements Filter { 
// init and destroy 
public void doFilter( 
ServletRequest request, 
ServletResponse response, 
FilterChain chain) { 
if (!user().canAccess(request)) 
throw new AuthException(user); 
chain.doFilter(request, response); 
} 
} 
Chain of 
Responsibility
Chain of 
Responsibility 
Ick. 
So much mutation. 
Where’s the start? 
What happens at the end?
@Test public void whoAteMyPie() { 
PieEater alice = PieEater.whoLoves(APPLE); 
PieEater bob = PieEater.whoLoves(BLUEBERRY); 
PieEater carol = PieEater.whoLoves(CHERRY); 
alice.setNext(bob); 
bob.setNext(carol); 
alice.give(blueberryPie); 
assertThat(bob, ate(blueberryPie)); 
} 
Chain of 
Responsibility
@Test public void whoAteMyPie() { 
PieEater carol = PieEater.atTheEnd() 
.whoLoves(CHERRY); 
PieEater bob = PieEater.before(carol) 
.whoLoves(BLUEBERRY); 
PieEater alice = PieEater.before(bob) 
.whoLoves(APPLE); 
alice.give(blueberryPie); 
assertThat(bob, ate(blueberryPie)); 
} 
Chain of 
Responsibility
@Test public void whoAteMyPie() { 
Chain<PieEater> carol = 
Chain.endingWith(PieEater.whoLoves(CHERRY)); 
Chain<PieEater> bob = 
Chain.from(PieEater.whoLoves(BLUEBERRY)) 
.to(carol); 
Chain<PieEater> alice = 
Chain.from(PieEater.whoLoves(APPLE)) 
.to(bob); 
alice.give(blueberryPie); 
assertThat(bob, ate(blueberryPie)); 
} 
Chain of 
Responsibility
@Test public void whoAteMyPie() { 
PieEater alice = PieEater.whoLoves(APPLE); 
PieEater bob = PieEater.whoLoves(BLUEBERRY); 
PieEater carol = PieEater.whoLoves(CHERRY); 
Chain<PieEater> pieEaters = 
Chain.from(alice) 
.to(Chain.from(bob) 
.to(Chain.endingWith(carol))); 
pieEaters.find(person -> person.loves(BLUEBERRY)) 
.give(blueberryPie); 
assertThat(bob, ate(blueberryPie)); 
} 
Chain of 
Responsibility
Chain<PieEater> pieEaters = 
Chain.from(alice) 
.to(Chain.from(bob) 
Chain of 
Responsibility 
.to(Chain.endingWith(carol))); 
(cons alice (cons bob (cons carol nil)))
Chain of 
Responsibility 
(cons alice (cons bob (cons carol nil)))
:-O 
Chain of 
Responsibility
@Test public void whoAteMyPie() { 
PieEater alice = PieEater.whoLoves(APPLE); 
PieEater bob = PieEater.whoLoves(BLUEBERRY); 
PieEater carol = PieEater.whoLoves(CHERRY); 
Stream<PieEater> pieEaters 
= Stream.of(alice, bob, carol); 
pieEaters 
.findAny(person -> person.loves(BLUEBERRY)) 
.get() 
.give(blueberryPie); 
assertThat(bob, ate(blueberryPie)); 
} 
Chain of 
Responsibility
So.
So. What’s your point?
I want you to use design patterns… 
like it’s 1958.
λ O O P
Credits 
Bakery, by Boris Bartels 
Just baked, by Sergio Russo 
cherry pie with crumble topping, by Ginny 
This presentation is licensed under 
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Thank you.

More Related Content

Similar to Design Patterns in the 21st Century - Samir Talwar

How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
Daniel Wellman
 
Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)
RichardWarburton
 
Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Antoine Sabot-Durand
 
Google guava
Google guavaGoogle guava
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Indrit Selimi
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
Mike North
 
Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.
Basel Issmail
 
Gwt and Xtend
Gwt and XtendGwt and Xtend
Gwt and Xtend
Sven Efftinge
 
Dat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingDat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android Testing
Saúl Díaz González
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
PROIDEA
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
Krzysztof Menżyk
 
EMFPath
EMFPathEMFPath
EMFPath
mikaelbarbero
 
VRaptor 4 - JavaOne
VRaptor 4 - JavaOneVRaptor 4 - JavaOne
VRaptor 4 - JavaOne
Rodrigo Turini
 
Intro to Pig UDF
Intro to Pig UDFIntro to Pig UDF
Intro to Pig UDF
Chris Wilkes
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Solid principles
Solid principlesSolid principles
Solid principles
Declan Whelan
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
Andrei Solntsev
 
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETTDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
tdc-globalcode
 
Pragmatic Functional Refactoring with Java 8
Pragmatic Functional Refactoring with Java 8Pragmatic Functional Refactoring with Java 8
Pragmatic Functional Refactoring with Java 8
Codemotion
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
Jon Kruger
 

Similar to Design Patterns in the 21st Century - Samir Talwar (20)

How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
 
Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)Pragmatic functional refactoring with java 8 (1)
Pragmatic functional refactoring with java 8 (1)
 
Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014Introduction to cdi given at java one 2014
Introduction to cdi given at java one 2014
 
Google guava
Google guavaGoogle guava
Google guava
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
 
Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.
 
Gwt and Xtend
Gwt and XtendGwt and Xtend
Gwt and Xtend
 
Dat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingDat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android Testing
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
 
EMFPath
EMFPathEMFPath
EMFPath
 
VRaptor 4 - JavaOne
VRaptor 4 - JavaOneVRaptor 4 - JavaOne
VRaptor 4 - JavaOne
 
Intro to Pig UDF
Intro to Pig UDFIntro to Pig UDF
Intro to Pig UDF
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
 
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETTDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
 
Pragmatic Functional Refactoring with Java 8
Pragmatic Functional Refactoring with Java 8Pragmatic Functional Refactoring with Java 8
Pragmatic Functional Refactoring with Java 8
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
 

More from JAXLondon2014

GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita IvanovGridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
JAXLondon2014
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang GottesheimPerformance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
JAXLondon2014
 
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
JAXLondon2014
 
Conditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean ReillyConditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean Reilly
JAXLondon2014
 
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim RemaniFinding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
JAXLondon2014
 
API Management - a hands on workshop - Paul Fremantle
API Management - a hands on workshop - Paul FremantleAPI Management - a hands on workshop - Paul Fremantle
API Management - a hands on workshop - Paul Fremantle
JAXLondon2014
 
'Bootiful' Code with Spring Boot - Josh Long
'Bootiful' Code with Spring Boot - Josh Long'Bootiful' Code with Spring Boot - Josh Long
'Bootiful' Code with Spring Boot - Josh Long
JAXLondon2014
 
The Full Stack Java Developer - Josh Long
The Full Stack Java Developer - Josh LongThe Full Stack Java Developer - Josh Long
The Full Stack Java Developer - Josh Long
JAXLondon2014
 
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
The Economies of Scaling Software - Josh Long and Abdelmonaim RemaniThe Economies of Scaling Software - Josh Long and Abdelmonaim Remani
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
JAXLondon2014
 
Dataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderDataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel Winder
JAXLondon2014
 
Habits of Highly Effective Technical Teams - Martijn Verburg
Habits of Highly Effective Technical Teams - Martijn VerburgHabits of Highly Effective Technical Teams - Martijn Verburg
Habits of Highly Effective Technical Teams - Martijn Verburg
JAXLondon2014
 
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
The Lazy Developer's Guide to Cloud Foundry - Holly CumminsThe Lazy Developer's Guide to Cloud Foundry - Holly Cummins
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
JAXLondon2014
 
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
Testing within an Agile Environment - Beyza Sakir and Chris GollopTesting within an Agile Environment - Beyza Sakir and Chris Gollop
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
JAXLondon2014
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
JAXLondon2014
 
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
Squeezing Performance of out of In-Memory Data Grids - Fuad MalikovSqueezing Performance of out of In-Memory Data Grids - Fuad Malikov
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
JAXLondon2014
 
Spocktacular Testing - Russel Winder
Spocktacular Testing - Russel WinderSpocktacular Testing - Russel Winder
Spocktacular Testing - Russel Winder
JAXLondon2014
 
Server Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David DelabasseeServer Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David Delabassee
JAXLondon2014
 
Reflection Madness - Dr. Heinz Kabutz
Reflection Madness - Dr. Heinz KabutzReflection Madness - Dr. Heinz Kabutz
Reflection Madness - Dr. Heinz Kabutz
JAXLondon2014
 
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
Rapid Web Application Development with MongoDB and the JVM - Trisha GeeRapid Web Application Development with MongoDB and the JVM - Trisha Gee
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
JAXLondon2014
 
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
JAXLondon2014
 

More from JAXLondon2014 (20)

GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita IvanovGridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang GottesheimPerformance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
 
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
 
Conditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean ReillyConditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean Reilly
 
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim RemaniFinding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
 
API Management - a hands on workshop - Paul Fremantle
API Management - a hands on workshop - Paul FremantleAPI Management - a hands on workshop - Paul Fremantle
API Management - a hands on workshop - Paul Fremantle
 
'Bootiful' Code with Spring Boot - Josh Long
'Bootiful' Code with Spring Boot - Josh Long'Bootiful' Code with Spring Boot - Josh Long
'Bootiful' Code with Spring Boot - Josh Long
 
The Full Stack Java Developer - Josh Long
The Full Stack Java Developer - Josh LongThe Full Stack Java Developer - Josh Long
The Full Stack Java Developer - Josh Long
 
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
The Economies of Scaling Software - Josh Long and Abdelmonaim RemaniThe Economies of Scaling Software - Josh Long and Abdelmonaim Remani
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
 
Dataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel WinderDataflow, the Forgotten Way - Russel Winder
Dataflow, the Forgotten Way - Russel Winder
 
Habits of Highly Effective Technical Teams - Martijn Verburg
Habits of Highly Effective Technical Teams - Martijn VerburgHabits of Highly Effective Technical Teams - Martijn Verburg
Habits of Highly Effective Technical Teams - Martijn Verburg
 
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
The Lazy Developer's Guide to Cloud Foundry - Holly CumminsThe Lazy Developer's Guide to Cloud Foundry - Holly Cummins
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
 
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
Testing within an Agile Environment - Beyza Sakir and Chris GollopTesting within an Agile Environment - Beyza Sakir and Chris Gollop
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
 
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
Squeezing Performance of out of In-Memory Data Grids - Fuad MalikovSqueezing Performance of out of In-Memory Data Grids - Fuad Malikov
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
 
Spocktacular Testing - Russel Winder
Spocktacular Testing - Russel WinderSpocktacular Testing - Russel Winder
Spocktacular Testing - Russel Winder
 
Server Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David DelabasseeServer Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David Delabassee
 
Reflection Madness - Dr. Heinz Kabutz
Reflection Madness - Dr. Heinz KabutzReflection Madness - Dr. Heinz Kabutz
Reflection Madness - Dr. Heinz Kabutz
 
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
Rapid Web Application Development with MongoDB and the JVM - Trisha GeeRapid Web Application Development with MongoDB and the JVM - Trisha Gee
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
 
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
 

Recently uploaded

María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024
eCommerce Institute
 
Tom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issueTom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issue
amekonnen
 
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Dutch Power
 
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
SkillCertProExams
 
ASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdfASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdf
ToshihiroIto4
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...
AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...
AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...
AwangAniqkmals
 
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Dutch Power
 
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
gharris9
 
Burning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdfBurning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdf
kkirkland2
 
2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf
Frederic Leger
 
Gregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics PresentationGregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics Presentation
gharris9
 
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie WellsCollapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Rosie Wells
 
Media as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern EraMedia as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern Era
faizulhassanfaiz1670
 
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdfSupercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Access Innovations, Inc.
 

Recently uploaded (19)

María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024
 
Tom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issueTom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issue
 
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
 
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
 
ASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdfASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdf
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...
AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...
AWANG ANIQKMALBIN AWANG TAJUDIN B22080004 ASSIGNMENT 2 MPU3193 PHILOSOPHY AND...
 
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
Presentatie 4. Jochen Cremer - TU Delft 28 mei 2024
 
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
 
Burning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdfBurning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdf
 
2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf2024-05-30_meetup_devops_aix-marseille.pdf
2024-05-30_meetup_devops_aix-marseille.pdf
 
Gregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics PresentationGregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics Presentation
 
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie WellsCollapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
 
Media as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern EraMedia as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern Era
 
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdfSupercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
 

Design Patterns in the 21st Century - Samir Talwar

  • 1. Design Patterns in the 21st Century 15th October 2014 @SamirTalwar
  • 2. What do you want from me? I want you to stop using design patterns.
  • 3. What do you want from me? I want you to stop using design patterns… like it’s 1999.
  • 4.
  • 5. The elements of this language are entities called patterns. Each pattern describes a problem that occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. – Christopher Alexander
  • 6. And now, an aside, on functional programming.
  • 7. int courses = 3; Course dessert = prepareCake.madeOf(chocolate); Preparation prepareCake = new Preparation() { @Override public Course madeOf(Ingredient mmmmm) { return new CakeMix(eggs, butter, sugar) .combinedWith(mmmmm); } };
  • 8. Preparation prepareCake = new Preparation() { @Override public Course madeOf(Ingredient mmmmm) { return new CakeMix(eggs, butter, sugar) .combinedWith(mmmmm); } }; Preparation prepareCake = mmmmm -> new CakeMix(eggs, butter, sugar) .combinedWith(mmmmm);
  • 9. Preparation prepareCake = mmmmm -> new CakeMix(eggs, butter, sugar) .combinedWith(mmmmm); Mix mix = new CakeMix(eggs, butter, sugar); Preparation prepareCake = mix::combinedWith;
  • 10. Mix mix = new CakeMix(eggs, butter, sugar); Preparation prepareCake = mix::combinedWith; Course combinedWith(Ingredient); @FunctionalInterface interface Preparation { Course madeOf(Ingredient mmmmm); }
  • 11. Well.
  • 12. On to the Good Stuff
  • 14. public interface Bakery { Pastry bakePastry(Topping topping); Cake bakeCake(); } public class DanishBakery implements Bakery { @Override public Pastry bakePastry(Topping topping) { return new DanishPastry(topping); } @Override public Cake bakeCake() { return new Æblekage(); // mmmm, apple cake… } } Abstract Factory
  • 15.
  • 16. public interface Bakery { Pastry bakePastry(Topping topping); } public class DanishBakery implements Bakery { @Override public Pastry bakePastry(Topping topping) { return new DanishPastry(topping); } } Abstract Factory
  • 17. Abstract Factory public class DanishBakery implements Bakery { @Override public Pastry bakePastry(Topping topping) { return new DanishPastry(topping); } } Bakery danishBakery = topping -> new DanishPastry(topping); Bakery danishBakery = DanishPastry::new;
  • 18. package java.util.function; /** * Represents a function that * accepts one argument and produces a result. * * @since 1.8 */ @FunctionalInterface public interface Function<T, R> { /** * Applies this function to the given argument. */ R apply(T t); ... } Abstract Factory
  • 19. public class DanishBakery implements Function<Topping, Pastry> { @Override public Pastry apply(Topping topping) { return new DanishPastry(topping); } } Function<Topping, Pastry> danishBakery = topping -> new DanishPastry(topping); Function<Topping, Pastry> danishBakery = DanishPastry::new; Abstract Factory
  • 20.
  • 22. interface Fire { <T> Burnt<T> burn(T thing); } interface Oven { Food cook(Food food); } class WoodFire implements Fire { ... } class MakeshiftOven extends WoodFire implements Oven { @Override public Food cook(Food food) { Burnt<Food> nastyFood = burn(food); return nastyFood.scrapeOffBurntBits(); } } Adapter
  • 23. interface Fire { <T> Burnt<T> burn(T thing); } interface Oven { Food cook(Food food); } class MakeshiftOven implements Oven { private final Fire fire; public MakeshiftOven(Fire fire) { /* ... */ } @Override public Food cook(Food food) { Burnt<Food> nastyFood = fire.burn(food); return nastyFood.scrapeOffBurntBits(); } } Adapter
  • 24. interface Oven { Food cook(Food food); } Oven oven = new MakeshiftOven(fire); Food bakedPie = oven.cook(pie); Adapter
  • 25.
  • 26. interface Oven { Food cook(Food food); } class MakeshiftOven implements Oven { private final Fire fire; public MakeshiftOven(Fire fire) { /* ... */ } @Override public Food cook(Food food) { Burnt<Food> nastyFood = fire.burn(food); return nastyFood.scrapeOffBurntBits(); } } Adapter
  • 27. class MakeshiftOven implements Oven { private final Fire fire; public MakeshiftOven(Fire fire) { /* ... */ } @Override public Food cook(Food food) { Burnt<Food> nastyFood = fire.burn(food); return nastyFood.scrapeOffBurntBits(); } } Oven oven = food -> { Burnt<Food> nastyFood = fire.burn(food); return nastyFood.scrapeOffBurntBits(); }; Food bakedPie = oven.cook(pie); Adapter
  • 28. Oven oven = food -> { Adapter Burnt<Food> nastyFood = fire.burn(food); return nastyFood.scrapeOffBurntBits(); }; Oven oven = food -> fire.burn(food).scrapeOffBurntBits();
  • 29. Oven oven = food -> fire.burn(food).scrapeOffBurntBits(); // Do *not* do this. Function<Food, Burnt<Food>> burn = fire::burn; Function<Food, Food> cook = burn.andThen(Burnt::scrapeOffBurntBits); Oven oven = cook::apply; Food bakedPie = oven.cook(pie); Adapter
  • 30. package java.util.concurrent; /** * An object that executes * submitted {@link Runnable} tasks. */ public interface Executor { void execute(Runnable command); } Adapter
  • 31. public interface Executor { void execute(Runnable command); } Executor executor = ...; Stream<Runnable> tasks = ...; tasks.forEach(executor); Adapter
  • 32. public interface Stream<T> { ... void forEach(Consumer<? super T> action); ... } @FunctionalInterface public interface Consumer<T> { void accept(T t); ... } Adapter
  • 33. public interface Executor { void execute(Runnable command); } @FunctionalInterface public interface Consumer<T> { void accept(T t); } Executor executor = ...; Stream<Runnable> tasks = ...; tasks.forEach(task -> executor.execute(task)); tasks.forEach(executor::execute); /
  • 35.
  • 36. The Chain of Responsibility pattern
  • 37. @Test public void whoAteMyPie() { PieEater alice = PieEater.whoLoves(APPLE); PieEater bob = PieEater.whoLoves(BLUEBERRY); PieEater carol = PieEater.whoLoves(CHERRY); alice.setNext(bob); bob.setNext(carol); alice.give(blueberryPie); assertThat(bob, ate(blueberryPie)); } Chain of Responsibility
  • 38. public final class HitCounterFilter implements Filter { private FilterConfig filterConfig = null; public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; } public void destroy() { this.filterConfig = null; } public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (filterConfig == null) return; Counter counter = (Counter)filterConfig.getServletContext().getAttribute("hitCounter"); StringWriter sw = new StringWriter(); PrintWriter writer = new PrintWriter(sw); writer.println("The number of hits is: " + counter.incCounter()); writer.flush(); filterConfig.getServletContext().log(sw.getBuffer().toString()); chain.doFilter(request, response); } } Chain of Responsibility
  • 39. public final class HitCounterFilter implements Filter { // init and destroy public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain) { int hits = getCounter().incCounter(); log(“The number of hits is ” + hits); chain.doFilter(request, response); } } Chain of Responsibility
  • 40. public final class SwitchEncodingFilter implements Filter { // init and destroy public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain) { request.setEncoding(“UTF-8”); chain.doFilter(request, response); } } Chain of Responsibility
  • 41. public final class AuthorizationFilter implements Filter { // init and destroy public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain) { if (!user().canAccess(request)) throw new AuthException(user); chain.doFilter(request, response); } } Chain of Responsibility
  • 42.
  • 43. Chain of Responsibility Ick. So much mutation. Where’s the start? What happens at the end?
  • 44. @Test public void whoAteMyPie() { PieEater alice = PieEater.whoLoves(APPLE); PieEater bob = PieEater.whoLoves(BLUEBERRY); PieEater carol = PieEater.whoLoves(CHERRY); alice.setNext(bob); bob.setNext(carol); alice.give(blueberryPie); assertThat(bob, ate(blueberryPie)); } Chain of Responsibility
  • 45. @Test public void whoAteMyPie() { PieEater carol = PieEater.atTheEnd() .whoLoves(CHERRY); PieEater bob = PieEater.before(carol) .whoLoves(BLUEBERRY); PieEater alice = PieEater.before(bob) .whoLoves(APPLE); alice.give(blueberryPie); assertThat(bob, ate(blueberryPie)); } Chain of Responsibility
  • 46. @Test public void whoAteMyPie() { Chain<PieEater> carol = Chain.endingWith(PieEater.whoLoves(CHERRY)); Chain<PieEater> bob = Chain.from(PieEater.whoLoves(BLUEBERRY)) .to(carol); Chain<PieEater> alice = Chain.from(PieEater.whoLoves(APPLE)) .to(bob); alice.give(blueberryPie); assertThat(bob, ate(blueberryPie)); } Chain of Responsibility
  • 47. @Test public void whoAteMyPie() { PieEater alice = PieEater.whoLoves(APPLE); PieEater bob = PieEater.whoLoves(BLUEBERRY); PieEater carol = PieEater.whoLoves(CHERRY); Chain<PieEater> pieEaters = Chain.from(alice) .to(Chain.from(bob) .to(Chain.endingWith(carol))); pieEaters.find(person -> person.loves(BLUEBERRY)) .give(blueberryPie); assertThat(bob, ate(blueberryPie)); } Chain of Responsibility
  • 48. Chain<PieEater> pieEaters = Chain.from(alice) .to(Chain.from(bob) Chain of Responsibility .to(Chain.endingWith(carol))); (cons alice (cons bob (cons carol nil)))
  • 49. Chain of Responsibility (cons alice (cons bob (cons carol nil)))
  • 50. :-O Chain of Responsibility
  • 51. @Test public void whoAteMyPie() { PieEater alice = PieEater.whoLoves(APPLE); PieEater bob = PieEater.whoLoves(BLUEBERRY); PieEater carol = PieEater.whoLoves(CHERRY); Stream<PieEater> pieEaters = Stream.of(alice, bob, carol); pieEaters .findAny(person -> person.loves(BLUEBERRY)) .get() .give(blueberryPie); assertThat(bob, ate(blueberryPie)); } Chain of Responsibility
  • 52.
  • 53. So.
  • 55.
  • 56. I want you to use design patterns… like it’s 1958.
  • 57. λ O O P
  • 58. Credits Bakery, by Boris Bartels Just baked, by Sergio Russo cherry pie with crumble topping, by Ginny This presentation is licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
  • 59.