title: Object caching design pattern
body: <p>I am wondering if there is a less painful way to write something like the following:</p>
  
  <pre><code>public class Company {
    // CEO, Programmer, and Janitor all inherit from an Employee class.
    private CEO _CacheCEO {get;} = CEOFactory.NewCEO();
    private Programmer _CacheJavaProgrammer {get;} = ProgrammerFactory.NewJavaProgrammer();
    private Programmer _CacheIOSProgrammer {get;} = ProgrammerFactory.NewIOSProgrammer();
    private Janitor _CacheJanitor {get;} = JanitorFactory.NewJanitor();
    // etc.
    public IEnumerable&lt;Employee&gt; GetEmployeesPresentToday() {
      List&lt;Employee&gt; r = new List&lt;Employee&gt;();
      if (ExternalCondition1) {   // value of the condition may differ on successive calls to this method
        r.Add(this._CacheCEO);
      };
      if (ExternalCondition2) {  // all conditions are external to the Company class, and it does not get notified of changes.
        r.Add(this._CacheJavaProgrammer);
      }
      if (ExternalCondition3) {
        r.Add(this._CacheIOSProgrammer);
      }
      if (ExternalCondition4) {
        r.Add(this._CacheJanitor);
      }
      // etc.
      return r;
    }
  </code></pre>
  
  <p>The part that bugs me here is all the private IVars.  If I have (say) 30 different employees, it gets laborious.  Is there a way to avoid having a separate ivar for each employee?</p>
  
  <p>I am not likely to need any access to the employee objects, other than through the GetEmployeesPresentToday() method.  In other words, I do not expect any code to be asking "Who is your CEO?" or the like.</p>
  
  <p>However, it is important that if two different calls are made to GetEmployeesPresentToday(), and Condition1 in the above code is true each time, then the same CEO object should appear in each list.</p>