| |
34. 7. 1. Watch What is Going On with the Chain of Responsibility Patterns |
|
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");
}
}
|
|
34. 7. 责任链模式 | | 34. 7. 1. | Watch What is Going On with the Chain of Responsibility Patterns | | | | 34. 7. 2. | 责任链 | | | | 34. 7. 3. | 多调度 | | |
|