1 package tests.jfun.yan.xml; 2 3 import tests.jfun.models.BankAccount; 4 5 public class SingletonBankAccount extends BankAccount { 6 private static int count = 0; 7 private SingletonBankAccount(){ 8 if(count > 0) 9 throw new IllegalStateException ("should not have more than 1 instances"); 10 count++; 11 } 12 public static BankAccount create(String id, int balance){ 13 BankAccount acct = new SingletonBankAccount(); 14 acct.balance = balance; 15 acct.setId(id); 16 return acct; 17 } 18 private boolean invoked = false; 19 public void run(){ 20 if(invoked){ 21 throw new IllegalStateException ("should not be called twice!"); 22 } 23 this.invoked = true; 24 } 25 } 26 | Popular Tags |