Lombok Builder.
Description:
Having this class:
public class People{
public int age;
public String name;
public String lastName;
String GREET="hello";
public String greet(){
return GREET+" my name is "+name;
}
}
We want to:
- Encapsulate properly the class by providing read accessors (setters are not required for this Kata).
- Implement the Builder design Pattern.
- Additionally we have allegedly a JIT compiler and we want to do some micro-optimization by marking constants in the code.
Constants
In Java, constants are creating by adding the final keyword, but only primitives are true constants if we have objects that are not primitives marked as constants they actually have their memory location constant, not the values. It's pretty useful to optimize memory in JIT compilers since they can actually reserve memory before we use the variables and having the confidence in that their memory locations will not be changed through the scope.
Builder Design Pattern
This design pattern help us create instances of the object by specifying all of the data in (Dementor) chain of calls style in any order. The object creation is optimized by creating the instance only when the build method is called. If we call a method twice in the builder the value of the field will be the second setted.
Note: If you don't use Lombok for this Kata ensure proper naming conventions are followed.
Similar Kata:
Stats:
Created | Nov 9, 2017 |
Published | Nov 14, 2017 |
Warriors Trained | 1247 |
Total Skips | 16 |
Total Code Submissions | 2953 |
Total Times Completed | 424 |
Java Completions | 424 |
Total Stars | 21 |
% of votes with a positive feedback rating | 66% of 76 |
Total "Very Satisfied" Votes | 40 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 15 |
Total Rank Assessments | 3 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |