Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. interface IApprovable {
  2. approve()
  3. reject()
  4. }
  5.  
  6. interface IPayable {
  7. pay()
  8. }
  9.  
  10. class Approvable implements IApprovable {
  11. ...
  12. approve() {...}
  13. reject() {...}
  14. }
  15.  
  16. class NotApprovable implements IApprovable {
  17. ...
  18. approve() {...} <-- throw an error
  19. reject() {...} <-- throw an error
  20. }
  21.  
  22. class Payable implements IPayable {
  23. ...
  24. pay() {...}
  25. }
  26.  
  27. class NotPayable implements IPayable {
  28. ...
  29. pay() {...} <-- throw an error
  30. }
  31.  
  32.  
  33. class Transaction {
  34. private IApprovable approvable;
  35. private IPayable payable;
  36.  
  37. Transaction(IApprovable approvable, IPayable payable) {
  38. this.approvable = approvable;
  39. this.payable = payable;
  40. }
  41. }
  42.  
  43. public static main() {
  44. Transaction topup = new Transaction(new Approvable(), new Payable());
  45. Transaction transfer = new Transaction(new NotApprovable(), new NotPayable());
  46. Transaction refund = new Transaction(new Approvable(), new NotPayable());
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement