Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package laborator9;
  7.  
  8. /**
  9. *
  10. * @author andre
  11. */
  12. public class Binding{
  13. public static void main(String args[]) {
  14. Hero h1 = new Warrior(), h2 = new Ninja();
  15. Hero h3 = new Rogue();
  16. BadLuck bl = new StormFire();
  17. bl.execute(h1);
  18. bl.execute(h2);
  19. bl.execute(h3);
  20. }
  21. }
  22.  
  23.  
  24. abstract class BadLuck {
  25. abstract void execute(Hero h);
  26. abstract void execute(Warrior w);
  27. abstract void execute(Ninja n);
  28. abstract void execute(Rogue r);
  29. }
  30.  
  31.  
  32. class StormFire extends BadLuck{
  33.  
  34. public StormFire(){
  35. }
  36.  
  37. @Override
  38. void execute(Hero h) {
  39.  
  40. h.accept(this);
  41. }
  42.  
  43. @Override
  44. void execute(Warrior w) {
  45. System.out.println("warrior");
  46. }
  47.  
  48. @Override
  49. void execute(Ninja n) {
  50. System.out.println("ninja");
  51. }
  52.  
  53. @Override
  54. void execute(Rogue r) {
  55. System.out.println("Rogue");
  56. }
  57.  
  58.  
  59. }
  60.  
  61. abstract class Hero {
  62. public void accept(BadLuck b) {
  63. b.execute(this);
  64. }
  65.  
  66. }
  67.  
  68. class Warrior extends Hero {
  69.  
  70. @Override
  71. public void accept(BadLuck b) {
  72. b.execute(this);
  73. }
  74. }
  75.  
  76.  
  77. class Ninja extends Hero {
  78.  
  79.  
  80. @Override
  81. public void accept(BadLuck b) {
  82. b.execute(this);
  83. }
  84. }
  85.  
  86. class Rogue extends Hero {
  87.  
  88.  
  89. @Override
  90. public void accept(BadLuck b) {
  91. b.execute(this);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement