title: Best pattern to create a wrapper Constructor
body: <p>The problem is the following. Given a class <code>GenericConfig</code> which encapsulates a <code>Map&lt;String, Object&gt;</code> to contain several configurations, a class <code>SpecificConfig</code> is desired to have getters to retrieve specific map values.</p>
  <p>For example, I want to avoid testing that <code>GenericConfig.getProperties().get(KEY_OF_PROPERTY);</code> is null and getting the value, with the burden of memorizing the key value in the calling method. I want to create a <code>SpecificConfig</code> that is created only if the key is present and that has a <code>getProperty()</code> method.</p>
  <p>Example of what I want to avoid:</p>
  <pre><code>private final static String KEY_OF_PROPERTY = &quot;key.for.my.value&quot;;
  
  public void process(List&lt;GenericConfig&gt; configs) {
      for(GenericConfig config: configs) {
          String value = config.getProperties().get(KEY_OF_PROPERTY);
          if (value != null) {
              // do something
          }
      }
  }
  </code></pre>
  <p>This is my attempt:</p>
  <pre><code>public final class SpecificConfig extends GenericConfig {
  
      public SpecificConfig(GenericConfig from) {
          if(from.getProperties().get(KEY_OF_PROPERTY) != null) {
              this.properties = from.getProperties();
          } else {
              throw new ThisIsNotTheConfigIWant();
          }
      }
  
      public String getProperty() {
          return (String) this.properties.get(KEY_OF_PROPERTY);
      }
  
  }
  </code></pre>
  <p>So I can do the following:</p>
  <pre><code>public void process(List&lt;GenericConfig&gt; configs) {
      for(GenericConfig config: configs) {
          try {
              SpecificConfig c = new SpecificConfig(config);
              // now i can be sure that c is of the required type
              
              // do stuff related to that type
          } catch (ThisIsNotTheConfigIWant) { /* ignore this config */ }
      }
  }
  </code></pre>
  <p>Is throwing a checked exception in the constructor a bad thing in OOP? Does a pattern to solve this problem exist? Is it viable to instantiate null in the constructor instead of throwing an exception.</p>