title: Best way to write a java object with a lot of optional properties
body: <p>I have to write a Java object which is used to hold calculation results. The results contains a large number of fields which may or may not be set depends on the type of algorithm used. For example:</p>
  
  <pre><code>class EquityValuationResult {
      private ValuationAlgorithm algorithm;
      private int yield;
      private double curve;
      private double meanValue;
      private double probability;
      private int standardDeviation;
      private boolean approximateValue;
      ......
      //Getter and Setters
  
  }
  </code></pre>
  
  <p>For different ValuationAlgorithm, the contents of these properties may be different. For example, if the algorithm is A, yield and probability will contain the calculation value, the rest of those will be null; if the algorithm is B, standardDeviation and curve will contain the result and the rest of those will be null, etc. The rule is very complicated, for example, if approcimateValue is true, some of the value will be overridden etc. <strong>Therefore, all these properties have to be in one class as they logically is one result.</strong></p>
  
  <p>An alternative way to do this is to use a Map</p>
  
  <pre><code>class EquityValuationResult {
      private final String YIELD = "yield";
      private final String CURVE = "curve";
      ........
  
      private ValuationAlgorithm algorithm;
      private final Map&lt;String, Object&gt; result = new HashMap&lt;String, Object&gt;();
  
      // Getter and Setters
  }
  </code></pre>
  
  <p>But if I do it like this, the getter and setter has to convert the values from Object to corresponding data type. I also have to define those constants and use them as the key of the map, this looks too cumbersome.</p>
  
  <p>Which will be the better way in your opinion? Are there any other better way to do this?</p>
  
  <p><strong>EDIT: Forgot to mention, creating separate class for each calculationType is not an option due to constraints. I have to use one class.</strong></p>