title: Design data class in Java
body: <p>I researched a bit and i'm not sure about this.</p>
  
  <p>I have a proccess that need returns a bunch of data. I put the data in a Result class:</p>
  
  <pre><code>public final class Result implements Serializable {
  /** Inmmutable class
       * 
       */
      private static final long serialVersionUID = -916675731077365794L;
  
      private final String nick;
      private final LocalDateTime date_init;
      private final LocalDateTime date_end;
  
      private final double profit;
      private final double tax;
  
      private final Double balance;
  
      private final int inputs;
  
      private final List&lt;CustomObjects&gt; inputs_by_month;
  
      // Keep going...
  
      // constructor
  
      Results(String nick, LocalDateTime date_init, LocalDateTime date_end,
              double profit, double tax/* Keep going... */) {
          super();
          this.nick = nick;
          this.date_init = date_init;
          this.date_end = date_end;
          this.profit = profit;
          this.tax = tax;
          /* Keep going... */
      }
  
      /* getters here */
  }
  </code></pre>
  
  <p>I'm not sure how i could create this object. Yeah, i could use a Factory class</p>
  
  <pre><code>public final class ResultFactory {
  
      private String nick;
      private LocalDateTime date_init;
      private LocalDateTime date_end;
  
      private double profit;
      private double tax;
  
      private Double balance;
  
      private int inputs;
  
      private List&lt;CustomObjects&gt; inputs_by_month;
  
      // Keep going...
  
      public Result getResult()
      {
         return Result(nick,date_init,date_end,/*...*/);
      }
  
      public void setNick(String nick)
      {
          this.nick = nick;
      }
  
      public void setDateInit(LocalDateTime date_init){
          this.date_init = date_init;
      }
  
      /* ... */
  }
  </code></pre>
  
  <p>But i am duplicating the entire structure. It doesn't look right.</p>
  
  <p>I'm looking for a pattern for store data in a inmutable class.</p>