title: Using fields/variable in Factory class to be used across objects created through factory
body: <p>I am using <strong>Factory</strong> to create my objects like following, here both <code>MyObject</code> and <code>YourObject</code> classes implements <code>MyInterface</code>:</p>
  
  <pre><code>public class MyFactory {
      public static MyInterface myObject(int value, int commonValue) {
          return new MyObject(value, commonValue);
      }
  
      public static MyInterface yourObject(String str, int commonValue) {
          return new YourObject(str, commonValue);
      }
  }
  </code></pre>
  
  <p>I want to set <code>commonValue</code> at the factory level instead of passing them as parameters in individual methods, as the same value is passed to create set of objects using factory. Also once I create one set of objects using the factory I want to reset <code>commonValue</code> to its default so that previously set value is not used by default later on.
  What is the right way to do this?</p>