View Javadoc

1   //----------------------------------------------------------------------
2   // 
3   // PerfectJPattern: "Design patterns are good but components are better!" 
4   // IParameterlessHandler.java Copyright (c) 2009 Giovanni Azua Garcia
5   // bravegag@hotmail.com
6   //  
7   // This program is free software; you can redistribute it and/or
8   // modify it under the terms of the GNU General Public License
9   // as published by the Free Software Foundation; either version 3
10  // of the License, or (at your option) any later version.
11  //
12  // This program is distributed in the hope that it will be useful,
13  // but WITHOUT ANY WARRANTY; without even the implied warranty of
14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  // GNU General Public License for more details.
16  //
17  // You should have received a copy of the GNU General Public License
18  // along with this program; if not, see <http://www.gnu.org/licenses/>.
19  //
20  //----------------------------------------------------------------------
21  package org.perfectjpattern.core.api.behavioral.chainofresponsibility;
22  
23  /**
24   * <b>Chain of Responsibility Design Pattern</b>: Avoid coupling the sender of
25   * a request to its receiver by giving more than one object a chance to handle
26   * the request. Chain the receiving objects and pass the request along the chain
27   * until an object handles it. (Gamma et al, Design Patterns)<br/>
28   * <br/>
29   * 
30   * <b>Responsibility</b>: Abstract definition of the "Handler".
31   * 
32   * <ul>
33   * <li>Defines an interface for handling requests.</li>
34   * <li>Implements the Successor link.</li>
35   * </ul>
36   * 
37   * <br/>
38   * Example usage:
39   * <pre><code>
40   *    //
41   *    // Create chain elements 
42   *    //  
43   *    IParameterlessHandler myFirst = new ConcreteHandler();
44   *    IParameterlessHandler mySecond = new ConcreteHandler();
45   *    IParameterlessHandler myThird = new ConcreteHandler();
46   *    
47   *    //
48   *    // Associate Handler elements 
49   *    //
50   *    myFirst.setSuccessor(mySecond);
51   *    mySecond.setSuccessor(myThird);
52   *    
53   *    //
54   *    // Execute the first Handler that triggers the execution of the 
55   *    // complete chain.
56   *    //
57   *    myFirst.start();
58   * </code></pre>
59   * 
60   * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
61   * @version $Revision: 1.0 $ $Date: Nov 6, 2007 6:14:22 PM $
62   */
63  public 
64  interface IParameterlessHandler
65  extends IHandler<NullRequest>
66  {
67      //------------------------------------------------------------------------
68      // public
69      //------------------------------------------------------------------------
70      /**
71       * Triggers execution of the Chain if the target Handler is the first 
72       * reference, otherwise implements the decision-making regarding forwarding
73       * the request to its successor <code>IHandler</code> instance.
74       */
75      public void
76      start();
77  
78      //------------------------------------------------------------------------
79      /**
80       * Handle the given request. Implements the actual handling logic and must 
81       * not contain any decision-making regarding e.g. forwarding the request.
82       */
83      public void
84      handle();
85  }