title: Should i use builder pattern in DTO?
body: <p>This might be a pretty subjetive question, but i would to know some more opinions. I've built a Rest API service with Spring MVC, and i implemented the DTO-Domain-Entity pattern. I want to know what do you think about implementing the <a href="https://en.wikipedia.org/wiki/Builder_pattern" rel="noreferrer">Builder pattern</a> in DTOs, something like</p>
  
  <pre><code>public class UserResponseDTO
      extends AbstractResponseDTO {
  
      private String username;
      private Boolean enabled;
  
      public UserResponseDTO(String username, Boolean enabled) {
          this.username = username;
          this.enabled = enabled;
      }
  
      public String getUsername() {
          return this.username;
      }
  
      public Boolean getEnabled() {
          return this.enabled;
      }
  
      public static class Builder {
  
          private String username;
          private Boolean enabled;
  
          public void setUsername(String username) {
              this.username = username;
          }
  
          public void setEnabled(Boolean enabled) {
              this.enabled = enabled;
          }
  
          public UserResponseDTO build(){
              return new UserResponseDTO(username, enabled);
          }
      }
  }
  </code></pre>
  
  <p>According to the definition: </p>
  
  <blockquote>
    <p>The intent of the Builder design pattern is to separate the construction of a complex object from its representation. By doing so the same construction process can create different representations. </p>
  </blockquote>
  
  <p>In most of my DTO cases (to not say all of them) i don't have a more complex object to build, such this case. And, honestly, i can't think of any example where construct a complex object if we are talking about DTOs.</p>
  
  <blockquote>
    <p>One of the patterns which helps make immutable objects easier to use and to add clarity to code is the Builder pattern.</p>
  </blockquote>
  
  <p>Builder pattern provides objects immutabiltiy. Then, we can think than a DTOs is the service response itself and should not be altered as this is a response (at least that is how i am thinking about it)  </p>
  
  <hr>
  
  <p>So what do you think? Should i use this pattern to DTOs (given the fact that this case, and probably most of them, does not satisfy the complex object principle)?</p>