Chain of responsability Print E-mail
User Rating: / 1
PoorBest 
Thursday, 20 January 2005 21:29
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.



Source code

/**
 * Handles request it is responsible to.
 */
public class ConcreteHandler extends Handler {
        /**
  * Handle request or delegate it.
  */
        public void handleRequest() {
                boolean canProcessThisRequest = false;                if (canProcessThisRequest) {
                        // handle request if possible
                } else {
                        // pass it to the next in chain
                        super.handleRequest();                }
        }

}

/**
 * Defines interface for request handling
 * @role __Handler
 */
public class Handler {
        private Handler successor;        /** Default request handling */
        public void handleRequest() {
                if (successor != null) {
                        successor.handleRequest();                }
        }

        public Handler getSuccessor() {
                return this.successor;        }

        public void setSuccessor(Handler successor) {
                this.successor = successor;        }

}




Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

designpattern  java 
Powered By Joomla Tags

Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated on Friday, 17 June 2005 23:38
 


Another articles:

Powered By relatedArticle

Content View Hits : 3463976

Enter Amount: