Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package laborator9;
- /**
- *
- * @author andre
- */
- public class Binding{
- public static void main(String args[]) {
- Hero h1 = new Warrior(), h2 = new Ninja();
- Hero h3 = new Rogue();
- BadLuck bl = new StormFire();
- bl.execute(h1);
- bl.execute(h2);
- bl.execute(h3);
- }
- }
- abstract class BadLuck {
- abstract void execute(Hero h);
- abstract void execute(Warrior w);
- abstract void execute(Ninja n);
- abstract void execute(Rogue r);
- }
- class StormFire extends BadLuck{
- public StormFire(){
- }
- @Override
- void execute(Hero h) {
- h.accept(this);
- }
- @Override
- void execute(Warrior w) {
- System.out.println("warrior");
- }
- @Override
- void execute(Ninja n) {
- System.out.println("ninja");
- }
- @Override
- void execute(Rogue r) {
- System.out.println("Rogue");
- }
- }
- abstract class Hero {
- public void accept(BadLuck b) {
- b.execute(this);
- }
- }
- class Warrior extends Hero {
- @Override
- public void accept(BadLuck b) {
- b.execute(this);
- }
- }
- class Ninja extends Hero {
- @Override
- public void accept(BadLuck b) {
- b.execute(this);
- }
- }
- class Rogue extends Hero {
- @Override
- public void accept(BadLuck b) {
- b.execute(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement