title: Abstracting out the field creation on a model builder in Java
body: <p><a href="https://howtodoinjava.com/design-patterns/creational/builder-pattern-in-java/" rel="nofollow noreferrer">In</a> <a href="https://www.vogella.com/tutorials/DesignPatternBuilder/article.html" rel="nofollow noreferrer">so</a> <a href="https://blogs.oracle.com/javamagazine/post/exploring-joshua-blochs-builder-design-pattern-in-java" rel="nofollow noreferrer">many</a> <a href="https://www.geeksforgeeks.org/builder-pattern-in-java/" rel="nofollow noreferrer">articles</a> <a href="https://blogs.oracle.com/javamagazine/post/exploring-joshua-blochs-builder-design-pattern-in-java" rel="nofollow noreferrer">on Java's builder design pattern</a>, it is implemented as follows:</p>
  <pre><code>public class YourModel {
     // your fields here
     private final long id;
     //...
  
     private YourModel(YourModelBuilder builder) { 
        // set everything from the builder
     }
     
     public static class YourModelBuilder { 
        // same fields from the model it is trying to build
        private final long id;
        //...
  
        public YourModelBuilder(long id/* , .... */) { 
           // the normal construction pattern here...
           this.id = id;
           //...
        }
  
        // some builder methods for setting individual fields while allowing for chaining
  
  
        public YourModel build() { 
            YourModel model = new YourModel(this);
            // do validation here
            return model;
        }
     }
  }
  </code></pre>
  <p>or something similar.</p>
  <p>This implementation of the design pattern seem to satisfy my use case, quickly and easily creating models manually for my Katalon Studio tests, in a way that is easy to understand, but it seems like it could end up a nightmare to maintain, especially given that the AUT these models are being created for, is constantly changing.</p>
  <p>How can we abstract out the field declaration being copied from the model to the model builder?</p>