item002 description started

This commit is contained in:
Christoph Kroczek
2019-07-13 21:31:24 +02:00
parent 446caaf265
commit 0fca949131

View File

@@ -1,5 +1,29 @@
# About this kata # About this kata
This kata refers to the book Effective Java by Joshua Bloch.
It addresses
Item 2: Consider a builder when faced with many constructor parameters.
# Problem description # Problem description
telescoping constructor pattern ???
-> In Java, there is no support for default values for constructor parameters. As a workaround, a technique called "Telescoping constructor" is often used. A class has multiple constructors, where each constructor calls a more specific constructor in the hierarchy, which has more parameters than itself, providing default values for the extra parameters. The next constructor does the same until there is no left.
public Person(String firstName, String lastName) {
this(firstName, lastName, "No description available");
}
public Person(String firstName, String lastName, String description) {
this(firstName, lastName, description, -1);
}
public Person(String firstName, String lastName, String description, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.description = description;
this.age = age;
}
JavaBeans pattern precludes the possibility of making a class immuteable (->Item 17!)
# Clues # Clues