title: Java Observer Pattern issue?
body: <p>I have the following Observer:</p>
  
  <pre><code>public class Fisc implements Observer {
  double value1;
  double value2;
  private static HashMap&lt;String, Deposit&gt; accounts=new HashMap&lt;String,Deposit&gt;();
  public Fisc(String cnp,Deposit deposit) {
  
      System.out.println("\n*******Observer*******Watching account:"+id);
      accounts.put(id, deposit);
  
  }
  
  public void update(Observable obj, Object arg) {
      if (arg instanceof Deposit) {
          value1 =((Deposit) arg).getvalue1();
          value2=((Deposit) arg).getvalue2();
          System.out.println("\n*******Observer*******value1 current value:"+value1);
          System.out.println("*******Observer*******value2 current value:"+value2);
      } else {
          System.out.println("Observable error!");
      }
  }
  }
  </code></pre>
  
  <p>and the Observable:</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.Observable;
  
  
  public class obs extends Observable {
  
      private static HashMap&lt;String, Deposit&gt; accounts;
  
      private static obs instance;
  
      private obs(HashMap&lt;String,Deposit&gt; accounts){
          obs.accounts=accounts;
      }
  
      public static obs getInstance(){
          if (instance==null){
              return new obs(new HashMap&lt;String,Deposit&gt;());
          }
          else return instance;
      }
  
          // ... some unimportant other stuff
  
      public void depositvalue1(String id,double value1){
          Deposit deposit=accounts.get(id);
          deposit.addvalue1(value1);
  
          if(deposit.isWatchedByFisc()){
              notifyFisc(deposit);
          }
          System.out.println("obs:Deposited "+value1+ " value1 to account:"+id+"!");
          System.out.println("obs:Current value1 in account:"+deposit.getvalue1());
      }
  
      public void depositvalue2(String id,double value2){
          Deposit deposit=accounts.get(id);
          deposit.addvalue2(value2);
  
          if(deposit.isWatchedByFisc()){
              notifyFisc(deposit);
          }
  
          System.out.println("obs:Deposited "+value2+" value2 to account:"+id+"!");
          System.out.println("obs:Current value1 in account:"+deposit.getvalue2());
      }
  
      public void depositValues(String id,double value1,double value2){
          Deposit deposit=accounts.get(id);
          deposit.addvalue1(value1);
          deposit.addvalue2(value2);
  
          if(deposit.isWatchedByFisc()){
              notifyFisc(deposit);
          }
  
          System.out.println("obs:Deposited "+value1+ " value1 and "+value2+" value2 to account"+id+"!");
          System.out.println("obs:Current value1 in account:"+deposit.getvalue1());
      }
  
      public void watchAccount(String id){
          Deposit deposit=accounts.get(id);
          deposit.setWatchedByFisc(true);
          addObserver(new Fisc(id,deposit));
      }
  
      public void stopWatchAccount(String id){
          accounts.get(id).setWatchedByFisc(false);
          System.out.println("obs:Account "+id+" is no longer watched by Fisc!");
      }
  
      public void notifyFisc(Deposit deposit){
          setChanged();
          notifyObservers(deposit);
      }
  
  }
  </code></pre>
  
  <p>Everything works as suppossed except the following: If I use the <code>depositValue(1,2,s)</code> methods instead of getting the message once, I get the same message the number of times I have registered deposits to be watched. How can I fix this?</p>
  
  <blockquote>
    <p>Hope this makes sense. Thanks in advance and sorry if this is a stupid question this is the first time using Observer Pattern.</p>
  </blockquote>
  
  <p>My guess is this line maybe(multiple instances?): <code>addObserver(new Fisc(id,deposit));</code> </p>