title: java builder pattern usage
body: <p>Recently I saw some of the developers coding their VOs with nested builder class like </p>
  
  <pre><code>public class User {
  
      private String firstName;
      private String lastName;
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public static class UserBuilder {
  
          private String firstName;
          private String lastName;
  
          public User build() {
              User user = new User();
              user.firstName = firstName;
              user.lastName = lastName;
              return user;
          }
  
          public UserBuilder withFirstName(String firstName) {
              this.firstName = firstName;
              return this;
          }
  
          public UserBuilder withLastName(String lastName) {
              this.firstName = firstName;
              return this;
          }       
      }
  
  }
  </code></pre>
  
  <p>Now, they claim that this makes code more readable. My point is, this has following disadvantages:</p>
  
  <ol>
  <li><p>I can't simply add fields and expect my IDE to complete code for me, as now I need to update this inner class too.</p></li>
  <li><p>Simple POJOs are carrying code which is not relevant for VO.</p></li>
  </ol>
  
  <p>I am looking for any advice if I am missing something here. Feel free to add your thoughts about the same. </p>
  
  <p>Sample code after this modification looks like,</p>
  
  <pre><code>User user = new User.UserBuilder()
                  .withFirstName("Name")
                  .withLastName("surName")
                  .build();
  </code></pre>