package tests.jfun.yan.xml;
import tests.jfun.models.BankAccount;
public class SingletonBankAccount extends BankAccount {
private static int count = 0;
private SingletonBankAccount(){
if(count > 0)
throw new IllegalStateException("should not have more than 1 instances");
count++;
}
public static BankAccount create(String id, int balance){
BankAccount acct = new SingletonBankAccount();
acct.balance = balance;
acct.setId(id);
return acct;
}
private boolean invoked = false;
public void run(){
if(invoked){
throw new IllegalStateException("should not be called twice!");
}
this.invoked = true;
}
}