Recommended sites

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
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;        }

}




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 ( Friday, 17 June 2005 23:38 )
 


Another articles:


Content View Hits : 2512794

Enter Amount: