Watch What is Going On with the Chain of Responsibility Patterns : Chain of Responsibility Patterns « Design Pattern « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Design Pattern » Chain of Responsibility Patterns 
34.7.1.Watch What is Going On with the Chain of Responsibility PatternsPrevious/Next
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.Chain of Responsibility Patterns
34.7.1.Watch What is Going On with the Chain of Responsibility Patterns
34.7.2.Chain of responsibility
34.7.3.Multiple dispatching
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.