Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IApprovable {
- approve()
- reject()
- }
- interface IPayable {
- pay()
- }
- class Approvable implements IApprovable {
- ...
- approve() {...}
- reject() {...}
- }
- class NotApprovable implements IApprovable {
- ...
- approve() {...} <-- throw an error
- reject() {...} <-- throw an error
- }
- class Payable implements IPayable {
- ...
- pay() {...}
- }
- class NotPayable implements IPayable {
- ...
- pay() {...} <-- throw an error
- }
- class Transaction {
- private IApprovable approvable;
- private IPayable payable;
- Transaction(IApprovable approvable, IPayable payable) {
- this.approvable = approvable;
- this.payable = payable;
- }
- }
- public static main() {
- Transaction topup = new Transaction(new Approvable(), new Payable());
- Transaction transfer = new Transaction(new NotApprovable(), new NotPayable());
- Transaction refund = new Transaction(new Approvable(), new NotPayable());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement