title: ES6: Restricting the Base Class to a Singleton
body: <p>I have two (2) sub classes off a single super class (base class); I get two instances if I new B and C -- both include the base class by extension. </p>
  
  <blockquote>
    <p>Question: Is it possible to place a Singleton restriction on the super
    class, and if so, how?</p>
  </blockquote>
  
  <pre><code>class A {
    constructor(id) {
      // =&gt; I don't want to make this call (2) times, 
      //  once for B and again for C.
      let {
        firstName: this._FirstName 
      } = CollectionName.findOne({userId: id}); 
    }
  }
  
  export class B extends A {
    constructor(id) {
      super(id);
    }
    get FirstName() {
      return this._FirstName;
    }
  }
  
  export class C extends A {
    constructor(id) {
      super(id);
    }
    get FirstName() {
      return this._FirstName;
    }
  }
  
  
  
  import { B, C } from 'imports/server/a-b-c.js'
  
  const b = new B('123')
  
  const c = new B('456')
  
  const FirstNameB = b.FirstName;
  
  const FirstNameC = c.FirstName;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I'm going to try to answer the questions here.</p>
  
  <blockquote>
    <p>@ Quasimodo's clone: What is your intention having a singleton pattern? Are you just in doubt if subclassing could generate multiple super class instances? Or do you try to prevent multiple subclass instances - super class should force that new C returns all the time the same C instance? </p>
  </blockquote>
  
  <p>The base classes call out to MongoDB and retrieve LOTS of data (if there's only one class its the base class).  When I have two classes extending a base class, I don't want to call out to Mongo and store all that data multiple times.  ATM I'm using the singleton patter to keep this from happening with just stand alone classes, but I'd really like to use this pattern in cases where I have two classes that use the same base class.</p>
  
  <p>Said in a different way,
  The problem that I've verified is happening: when I have two classes calling out to one base class, the base class's constructor is being called twice, and Mongo is being hit twice.  ATM I don't have a singleton pattern set up for the base class when it's called by extension.  </p>
  
  <p>Now I need to figure out how to apply a singleton pattern on a base class extended by multiple classes.  And since the base class is actually the same instance of the subclass, I don't even know if this is possible.</p>