interface - Java Multiple Inheritance without Source Code -


i have class called thing , class called robot. thing has public void setblocksexit(). robot has methods desire.

i have extended robot want setblocksexit() thing. make interface has setblocksexit() , make class like:

public class c extends robot implements blockexit {} 

the problem don't have access source code thing , robot. using educational package 'becker.jar' , of code compiled can't access extract interfaces. options?

your options following:

  • extend thing , have reference robot delegate robot methods to.
  • extend robot , have reference thing object delegate setblocksexit calls to.
  • create fresh class , have reference robot , reference thing , delegate calls these 2 objects.

if you're using ide such eclipse can "extract interfaces" , generate delegate methods automatically.

option 1:

class c extends thing {     final robot robot;     public c(robot robot) {         this.robot = robot;     }      public int robotmethod1() {         return robot.robotmethod1();     }      ... } 

option 2:

class c extends robot {     final thing thing;     public c(thing thing) {         this.thing = thing;     }      public void setblocksexit(boolean flag) {         return thing.setblocksexit(flag);     }      ... } 

option 3:

class c {     final thing thing;     final robot robot;     public c(thing thing, robot robot) {         this.thing = thing;         this.robot = robot;     }      public void setblocksexit(boolean flag) {         return thing.setblocksexit(flag);     }      public int robotmethod1() {         return robot.robotmethod1();     }     ... } 

if you're using eclipse use feature:

i'm sure whatever ide you're using has similar feature.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -