public class MainClass {
public static void main(String args[]) {
Application app = new Application();
IntermediateLayer intermediateLayer = new IntermediateLayer(app);
FrontEnd frontEnd = new FrontEnd(intermediateLayer);
frontEnd.getHelp(HelpType.GENERAL_HELP);
}
}
class HelpType {
public final static int FRONT_END_HELP = 1;
public final static int INTERMEDIATE_LAYER_HELP = 2;
public final static int GENERAL_HELP = 3;
}
interface HelpInterface {
public void getHelp(int helpConstant);
}
class IntermediateLayer implements HelpInterface {
HelpInterface successor;
public IntermediateLayer(HelpInterface s) {
successor = s;
}
public void getHelp(int helpConstant) {
if (helpConstant != HelpType.INTERMEDIATE_LAYER_HELP) {
successor.getHelp(helpConstant);
} else {
System.out.println("intermediate");
}
}
}
class FrontEnd implements HelpInterface {
HelpInterface successor;
public FrontEnd(HelpInterface s) {
successor = s;
}
public void getHelp(int helpConstant) {
if (helpConstant != HelpType.FRONT_END_HELP) {
successor.getHelp(helpConstant);
} else {
System.out.println("front end");
}
}
}
class Application implements HelpInterface {
public void getHelp(int helpConstant) {
System.out.println("application");
}
}
|