The code uses a library to create IO for a java driven PLC. In the Io interface class i create IO for the plc. All properties etc is stored in a bComponent. You can see this as something like context normally is.
I need this bComponent/context to be the same in the mainClass so i can't use static methods/class. How can i do this without having to create an instance. i just want to share the bcomponent between the classes. i.e. inherit the parents bComponent/context.
any help would be really appreciated !
public class IoInterface extends BComponent implements Runnable {
public final BComponent getComponent() {return this;}
/**Create an Action*/
public static final Action TestAction_1 = newAction(Flags.HIDDEN, null);
public void TestAction_1() {invoke(TestAction_1, null, null);}
/**Create in IO*/
public static final Property bBool_1 = newProperty(Flags.EXECUTE_ON_CHANGE | Flags.OPERATOR Flags.SUMMARY, ((BBoolean) ((BValue) BBoolean.TYPE.getInstance())).getBoolean(), BFacets.tryMake(null));
public boolean getBBool_1() {return getBoolean(bBool_1);}
public void setBBool_1(boolean v) {setBoolean(bBool_1, v, null);}
public void run() {}
//This method is called when triggering "TestAction_1"
public void doTestAction_1(){}
}
In this class i want to interact with the IO and action created in the IoInterface class*/
public class mainClass extends IoInterface {
//bcomponent needs to bee the same as IoInterface
public mainClass(BComponent b) {
super(b);
}
public void main(){
triggerAction("TestAction");
}
//for this to work properly getComponent needs to return the same bComponent as in IoInterface
public void triggerAction(String nameOfAction) {
this.getComponent().invoke(this.getComponent().getAction(nameOfAction), null);
}
}
question from:
https://stackoverflow.com/questions/65951814/how-can-i-use-inherit-the-same-context-as-the-parent-class-i-am-extending 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…