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 referencerobot
delegaterobot
methods to. - extend
robot
, have referencething
object delegatesetblocksexit
calls to. - create fresh class , have reference
robot
, referencething
, 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
Post a Comment