I really enjoyed reading your article. I went through it writing out your code. I agree with Alexander Kosenkov’s comment. I found it easier to simply write
employee {
name = "David"
id = "343"
title = "Super Boss"
salary = 32332223
}
So, the builder is simplified to:
class EmployeeBuilder {
var name: String = ""
var id: String = ""
var title: String = ""
var salary: Int = 0
fun build() = Employee(name, id, title, salary)
}
I liked your idea of the EmployeeListBuilder
. It is a good idea. Then all of the employee
declarations must appear inside the employees
block. It helps to keep the declarations more organized.
Thank you for your well-written article.