ARE YOU STRINGIFIED?
Frederik Hahne
@atomfrede
@java_hipster board member
@jugpaderborn leader
developer @wescalehq
ARE YOU STRINGIFIED?
public class Customer {
private Long id;
private String firstname, lastname, email;
}
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?
}
}
public class Customer {
private Long id;
private String firstname, lastname, email;
}
public class SomeService {
Customer createCustomer(..., String email, ...) {
// What is a valid email adress?
}
}
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, ...);
}
}
Customer person = new Builder()
.firstname("John")
.lastname("Doe")
.email("john@doe.me")
.build();
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
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")
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")
Vortrag mit Diskussion
Frank Pientka (JUG Dortmund)
https://jug-pb.gitlab.io/
Vortrag mit Diskussion
Thorben Janssen (CDI 2.0 expert group member)
https://jug-pb.gitlab.io/
https://wiki.eclipse.org/Eclipse_DemoCamps_Oxygen_2017/Paderborn
https://www.meetup.com/itemis/events/240477045/?eventId=240477045