Skip to content

Instantly share code, notes, and snippets.

@mkouba
Created December 5, 2011 13:21
Show Gist options
  • Save mkouba/1433570 to your computer and use it in GitHub Desktop.
Save mkouba/1433570 to your computer and use it in GitHub Desktop.
CDI-28
public interface Account {
public void withdraw(int amount);
public void deposit(int amount);
public int getBalance();
}
public class BankAccount implements Account {
int balance = 0;
@Override
public void withdraw(int amount) {
balance -= amount;
}
@Override
public void deposit(int amount) {
balance += amount;
}
public int getBalance() {
return balance;
}
}
@Decorator
public abstract class ChargeDecorator implements Account {
private static final int WITHDRAVAL_CHARGE = 5;
public static int charged = 0;
@Inject
@Delegate
private Account account;
@Override
public void withdraw(int amount) {
account.withdraw(amount + WITHDRAVAL_CHARGE);
charged += WITHDRAVAL_CHARGE;
}
@Override
public abstract void deposit(int amount);
public static void reset() {
charged = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment