ARE YOU STRINGIFIED?
About me
Frederik Hahne
@atomfrede
@java_hipster board member
@jugpaderborn leader
developer @wescalehq
About escale
build the next generation B2B integration platform with
- latest Javascript technologies (React, VueJS, Redux, Webpack & friends)
- latest Java technologies (Spring Boot, Vert.x, Gradle)
- Cloud Native (Kubernetes, Spring Cloud)
- Microservices, Microfrontends
- API 1st
- 3rd party integration
- Agile, diverse, open minded teams
wescale.com/join-us
ARE YOU STRINGIFIED?
Java
Go
Haskell
Kotlin
TYPED
statically
public class Customer {
private Long id;
private String firstname, lastname, email;
}
Typed
public class Customer {
private Long id;
private String firstname, lastname, email;
}
public class SomeService {
Customer createCustomer(..., String email, ...) {
// What is a valid email adress?
// Which parameter is the email?
}
}
Typed?
public class Customer {
private Long id;
private String firstname, lastname, email;
}
public class SomeService {
Customer createCustomer(..., String email, ...) {
// What is a valid email adress?
}
}
Stringly Typed :(
public class Customer {
private Long id;
private Firstname firstname;
private Lastname lastname;
private Email email;
}
public class SomeService {
public Customer createCustomer(..., Email email, ...) {
return new Customer(..., email, ...);
}
}
Strongly Typed :)
Make Concepts Explicit in Code
Patterns
Libraries
Languages
Builder Pattern
Customer person = new Builder()
.firstname("John")
.lastname("Doe")
.email("john@doe.me")
.build();
Libraries
public Customer(@Firstname String firstname,
@Lastname String lastname,
@Email String email) {
// Use Bean Validation to externalize validation of string
}
// Using value objects to let the
// apt compiler generate a lot of code
@Value.Immutable
public interface Customer {
private Email email;
}
@Value.Immutable
public interface Email {
private String email;
}
// Generate builders, validators at compile time
Languages
typealias Firstname = String
typealias Lastname = String
typealias Email = String
class Customer(val firstname: Firstname,
val lastname: Lastname,
val email: Email)
val customer = Customer("John",
"Doe",
"john@doe.me")
Can we do better?
- Declaration: Typed
- Invocation: Not :(
- It's just an alias
Languages
class Customer(val firstname: String,
val lastname: String,
val email: String? = null)
val customer = Customer(firstname = "John",
lastname = "Doe")
val another = Customer(lastname = "Mueller",
email = "hans@mueller.de",
firstname = "Hans")
One more thing...
Tooling
not explicit in code
Remember:
Excplicit is better
More
- https://speakerdeck.com/olivergierke/ddd-and-rest-domain-driven-apis-for-the-web-5
- https://blog.frankel.ch/coping-stringly-typed/
- http://immutables.github.io/
Join our Meetup
29.06.17 um 18:30 Uhr
An der Talle 89
@wescalehq
Was ist Serverless Computing?
Vortrag mit Diskussion
Frank Pientka (JUG Dortmund)
https://jug-pb.gitlab.io/
Join our Meetup
Im August
@verlinked
Effiziente Datenpersistierung mit JPA und Hibernate
Vortrag mit Diskussion
Thorben Janssen (CDI 2.0 expert group member)
https://jug-pb.gitlab.io/
Eclipse Demo Camp
Tuesday, June 27th, 2017, 18:15
"Biohaus Bauwerker" - Driburger Straße 24 - 33100 Paderborn
https://wiki.eclipse.org/Eclipse_DemoCamps_Oxygen_2017/Paderborn
https://www.meetup.com/itemis/events/240477045/?eventId=240477045
Question?
Are you Stringified?
By atomfrede
Are you Stringified?
- 796