public class LiuXiang implements Runner{ @Override public void run(int speed){ //run } }
1 2 3 4 5 6
public class Bolt implements Runner{ @Override public void run(int speed){ //run } }
1 2 3 4 5 6 7 8
public abstract class ABRunner{ protected Runner runner; protected ABRunner(Runner runner){ this.runner = runner; }
public abstract void run(); }
1 2 3 4 5 6 7 8 9 10 11 12
public class RunnerBridge extends ABRunner{ int speed; public RunnerBridge(int speed,Runner runner){ super(runner); this.speed = speed; } @Override public void run(){ runner.run(speed); } }
1 2 3 4 5 6
public static void main(String[] args){ RunnerBridge bolt = new RunnerBridge(100, new Bolt()); RunnerBridge liuxiang = new RunnerBridge(100, new LiuXiang()); bolt.run(); liuxiang.run(); }