class BankAccount {
public Money withdraw(Money amount){
if(account_locked)
throw new AccountLockedException();
else if(transaction_limit_exceeded)
throw new AccountLockedException();
else {
//more logic
balance.subtract(amount);
//more logic
return amount;
}
}
}
abstract class WithdrawalStrategy {
abstract Money withdraw(Money money);
public static final ACCOUNT_LOCKED_WITHDRAWAL = new WithdrawalStrategy(){.......};
public static final LIMIT_EXCEEDED_WITHDRAWAL = new WithdrawalStrategy (){......};
public static final LIMIT_EXCEEDED_WITHDRAWAL = new WithdrawalStrategy (){......};
}
class BankAccount {
public BankAccount(){
this.withdrawalStrategy = .....;
}
public Money withdraw(Money amount){
return withdrawalStrategy.withdraw(amount);
}
}
abstract class WithdrawalStrategy {
abstract Money withdraw(Money money);
public static final ACCOUNT_LOCKED_WITHDRAWAL = new WithdrawalStrategy(){.......};
public static final LIMIT_EXCEEDED_WITHDRAWAL = new WithdrawalStrategy (){......};
public static final EVERYTHING_OK_WITHDRAWAL = new WithdrawalStrategy (){......};
}
abstract class DepositStrategy {
abstract Money deposit(Money money);
public static final ACCOUNT_LOCKED_DEPOSIT = new DepositStrategy(){.......};
public static final LIMIT_EXCEEDED_DEPOSIT = new DepositStrategy (){......};
public static final EVERYTHING_OK_DEPOSIT = new DepositStrategy (){......};
}
class BankAccount {
public BankAccount(){
...........
this.withdrawalStrategy = .....;
this.depositStrategy = .....;
}
public Money withdraw(Money amount){
return withdrawalStrategy.withdraw(amount);
}
public Money deposit(Money amount){
return depositStrategy.deposit(amount);
}
}
abstract class WithdrawalStrategy_Plus_DepositStrategy {
abstract Money withdraw(Money money);
abstract Money deposit(Money money);
public static final ACCOUNT_LOCKED = new WithdrawalStrategy_Plus_DepositStrategy(){.......};
public static final LIMIT_EXCEEDED = new WithdrawalStrategy_Plus_DepositStrategy (){......};
public static final EVERYTHING = new WithdrawalStrategy_Plus_DepositStrategy (){......};
}
AccountState
.
abstract class AccountState {
abstract Money withdraw(Money money);
abstract Money deposit(Money money);
public static final ACCOUNT_LOCKED = new AccountState(){.......};
public static final LIMIT_EXCEEDED = new AccountState (){......};
public static final EVERYTHING_OK = new AccountState (){......};
}
I am passionate about making Better Software Solutions,that helps businesses to stay agile, by applying Agile,Lean and Systems Thinking principles. Also I grow coffee,spices and in general has big interest in pesticide free food!
Subscribe to
Posts [Atom]