title: Observer Subject Singleton pattern?
body: <p>I'm working on designing a pattern where there will be multiple subjects and multiple observers. Each observer will register itself to the subjects that it needs to in it's constructor, as it knows what it needs to know to produce it's output. My first thought was to make the subjects a singleton class, but I found that would either require making each subject a singleton individually, or an <code>abstract static</code> class that Java does not support. Bottom line is, I'm trying to figure out what the best solution really is. Just to make sure it's really clear, here's what I'm trying to do:</p>
  
  <ol>
  <li>There will be multiple subjects. Each observer will have the ability to observe multiple subjects. In order to make this work, I'm going to have a resource code for each subject such that it will identify itself to the Observer (`update(SUBJECT_1) where SUBJECT_1 is the int that corresponds to Subject 1)</li>
  <li>Each observer will know which subjects it wants to observe at construction.</li>
  <li>I only want a single instance of each subject created.</li>
  <li>Some observers might in turn be subjects themselves. </li>
  <li>In general, there is a flow pattern. There is ultimately a few sources of input, which create more abstract concepts. My flow diagram of observer/subject looks something like this:</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/Qoxig.png" alt="enter image description here"></p>
  
  <p>I'm thinking this might call for another design pattern entirely, but as I'm still fairly new to design patterns in general, I thought I'd ask for a bit more experience before I jump in. Thanks!</p>
  
  <p>Just to be clear, the singleton comes in to play as follows, namely that I want an abstractSubject, where every subject is a Singleton. While I could make each a singleton of its own accord, I'd rather be forced to make all use a getInstance, something like this psuedo-code.</p>
  
  <pre><code>abstract class abstractSubject{
  
  AbstractSubject instance=null;
  
  public static AbstractSubject getInstance()
  {
      if (instance==null)
          instance=new AbstractInstance();
      return instance;
  }
  abstract void attach();
  //More stuff will go here to make it a subject
  }
  
  //Define Subject1, Subject2 classes fully
  
  class Observer1 extends AbstractObserver{
  
      public Observer1()
      {
          Subject1.getInstance().attach(this);
          Subject2.getInstance().attach(this);
      }
      //Other stuff goes here to make it an observer
  }
  </code></pre>