Created
December 5, 2011 13:21
-
-
Save mkouba/1433570 to your computer and use it in GitHub Desktop.
CDI-28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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