Posts

Showing posts from October, 2014

Using Kotlin for DTOs instead of Java

Image
Creating DTOs  in Java, you often end up with very verbose code, similar to the following Address data class: public class Address { private String contactName; private String companyName; private String street; private String streetNumber; private String streetAppendix; private String zipCode; private String city; private String country; private String state; private String contactPhone;  public String getContactName() { return contactName; } public void setContactName(final String contactName) { this.contactName = contactName; }          // 90 lines of getter / setter code has been omitted here!   } Studies have shown  that there is a correlation between code size and erroneous code . Hence reducing code size results in concise code which improves readability and understanding of the underlying solution idioms. The following Kotlin data class  with merely 11 lines of code represents exactly the same semantics as the 112 li