Functional Patterns With Java8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Victor Rentea

14 years of Java .NET

Lead Architect
Tech Team Lead and Consultant
founder of
Software Craftsman Bucharest
Software
XP: Pair Programming, Refactoring, TDD Craftsmanship
Community
Clean Code Evangelist
Moscow Paris London Krakow Vienna Sofia Casablanca Belgrade Kiew Barcelona
+ 10 more

VictorRentea.ro
Independent
Technical Trainer & Coach
5 years 1000 devs 100+ days at:

Spring Hibernate Java 8

Design Patterns Architecture, DDD

Clean Code Unit Testing, TDD 15 more…

Java Performance Scala and more…


follow me

[email protected]
VictorRentea.ro @victorrentea [email protected]
VictorRentea.ro
HARD-CORE SWITCH
HARD-CORE SWITCH
lower play rate
in YouTube
Clean Code
+
Java 8
Expressive Names
Lambdas should be one liners

-> {
Extract heavy lambdas into named ::methods
➢in the same class
➢in the item class
➢as static methods
Optional
No Nullable Parameters
Instead: thatOpt.map(doStuffWithIt)

Avoid Returning Null, Throw Ex


…, or return an Optional

Monad Even from Entity getters


Execute arbitrary logic within a function
CPP
+1 boolean param
Extract & @Override
Template Method®

Passing-a-Block
exporter.exportFile("orders.csv", orderWriter::writeContent);
Passing-a-Block

The Loan Pattern


exporter.exportFile("orders.csv", orderWriter::writeContent);

try (Writer writer = new FileWriter(file)) {


contentWriter.accept(writer);
return file; contentWriter is "loaned"
} catch (...) { a Writer managed here
...
}
similarly:

Testable
Infrastructure decoupled from export format
test with a dummy format test with a StringWriter
Passing-a-Block

Execute Around Pattern

Ad-hoc Proxy® or Decorator®


Prefer

Runtime Exceptions

Java8 functional interfaces don't throw anything

Rethrow Checked as Runtime


libs: jool, vavr, lombok
Type-specific Logic
switch OOP enum
Switch Hunt Day Extends is BAD Logic Bits
Hope to find them all: JDD In enum methods

Simplest Combinatorial Logic with Dependencies


1 switch = 1 method Children90Movie Function references on enums
case XX: return …
Read it all in my dzone article
dzone.com/articles/functional-programming-patterns-with-java-8

Let's chat! Disclaimer: The use of ® or ™ is the slides is only anecdotic.


Purpose of code:--Uncle Bob Clean Code
Stay into Functional Party 1. Maintainable
I'm available needs strength
The Light Activist 2. Does its job! Tough meetings?
a statement of seniority and determination
Abused estimates?

I use both hemispheres

Read it all in my dzone article Trainings, talks, goodies Quality posts daily on
dzone.com/articles/functional-programming-patterns-with-java-8

Let's chat!

You might also like