A bit of a question on working with objects in java. Suppose I have the following class.
public class Example {
private String ex1 = new String();
private String ex2 = new String();
private int varOne;
public Example logicOne(/*Input variables*/) {
// Do logic
return this;
}
public Example logicTwo(/*Input variables*/) {
// Do logic
return this;
}
public int subLogicOne(/*Input variables*/) {
return varOne;
}
public int subLogicTwo(/*Input variables*/) {
return varTwo;
}
public int subLogicThree(/*Input variables*/) {
return varThree;
}
}
I know that setting a methods type to the class name and using return this will allow me to chain methods when calling the class object like so.
Example obj = new Example;
obj.logicOne("inputOne").logicTwo("inputTwo");
But how would I restrict which methods could be called? For example making logicOne and logicTwo mutually exclusive and restricting subLogicOne to logicOne and subLogicTwo to logicTwo with subLogicThree being shared between them like this.
Example obj = new Example;
obj.logicOne("inputOne").subLogicOne("subInputOne");
obj.logicTwo("inputTwo").subLogicTwo("subInputTwo");
obj.logicOne("inputOne").subLogicThree("subInputThree");
obj.logicTwo("inputTwo").subLogicThree("subInputThree");