title: Builder pattern vs. config object
body: <p>The builder pattern is popular to create immutable objects, but there is some programming overhead to create a builder. So I wonder why not simply using a config object.</p>
  
  <p>The usage of a builder would look like this:</p>
  
  <pre><code>Product p = Product.Builder.name("Vodka").alcohol(0.38).size(0.7).price(17.99).build();
  </code></pre>
  
  <p>It is obvious that this is very readable and concise, but you have to implement the builder:</p>
  
  <pre><code>public class Product {
  
      public final String name;
      public final float alcohol;
      public final float size;
      public final float price;
  
      private Product(Builder builder) {
          this.name = builder.name;
          this.alcohol = builder.alcohol;
          this.size = builder.size;
          this.price = builder.price;
      }
  
      public static class Builder {
  
          private String name;
          private float alcohol;
          private float size;
          private float price;
  
          // mandatory
          public static Builder name(String name) {
              Builder b = new Builder();
              b.name = name;
              return b;
          }
  
          public Builder alcohol(float alcohol) {
              this.alcohol = alcohol;
              return.this;
          }
  
          public Builder size(float size) {
              this.size = size;
              return.this;
          }
  
          public Builder price(float price) {
              this.price = price;
              return.this;
          }
  
          public Product build() {
              return new Product(this);
          }
  
      }
  
  }
  </code></pre>
  
  <p>My idea is, to reduce the code by using a simple config object like this:</p>
  
  <pre><code>class ProductConfig {
  
          public String name;
          public float alcohol;
          public float size;
          public float price;
  
          // name is still mandatory
          public ProductConfig(String name) {
              this.name = name;
          }
  
  }
  
  public class Product {
  
      public final String name;
      public final float alcohol;
      public final float size;
      public final float price;
  
      public Product(ProductConfig config) {
          this.name = config.name;
          this.alcohol = config.alcohol;
          this.size = config.size;
          this.price = config.price;
      }
  
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>ProductConfig config = new ProductConfig("Vodka");
  config.alcohol = 0.38;
  config.size = 0.7;
  config.price = 17.99;
  Product p = new Product(config);
  </code></pre>
  
  <p>This usage needs a few more lines but is also very readable, but the implementation is much simpler and maybe it is easier to understand for someone who isn't familiar with the builder pattern. By the way: is there a name for this pattern?</p>
  
  <p>Is there a drawback in the config approach that I've overlooked?</p>