title: Are there any patterns for implementing mutable and immutable versions of a holder object?
body: <p>In my application I have few types of <em>holder</em> objects, which primary purpose is to store heterogeneous related data. Their lifecycles can be divided into two parts: </p>
  
  <ol>
  <li>Collecting data as soon as it becomes available;</li>
  <li>Providing read-only access to stored data for the rest of a holder's life.</li>
  </ol>
  
  <p>It is very tempting to make the holders immutable, but the data is not available at one time to be passed to a constructor. The simplest workaround I see is to make two versions of a holder class, one being mutable, and another being not:</p>
  
  <pre><code>public class MutableHolder {
      public int field1;
      public String field2;
      // ...
      public Object fieldN;
  }
  
  public class Holder {
      public final int field1;
      public final String field2;
      // ...
      public final Object fieldN;
  
      public Holder(MutableHolder mutableHolder) {
          this.field1 = mutableHolder.field1;
          this.field2 = mutableHolder.field2;
          // ...
          this.fieldN = mutableHolder.fieldN;
      }
  }
  </code></pre>
  
  <p>However, I feel that this approach is violating the DRY principle (I must not forget to update both classes' fields as well as the constructor if I want to change anything) and is error prone. So here is my question: are there any existing patterns that I'm not aware of for implementing both mutable and immutable versions of a holder object?</p>
  
  <h3>Edit</h3>
  
  <p>I've suddenly found out that the code above is a very barebone version of the Builder pattern (see <a href="http://cantina.co/immutable-objects-and-the-builder-pattern/" rel="nofollow">this</a> or <a href="http://java.dzone.com/articles/immutability-with-builder-design-pattern" rel="nofollow">this</a>). This makes me think that in this case DRY violation is considered acceptable.</p>