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
State Print E-mail
User Rating: / 2
PoorBest 
Thursday, 27 January 2005 19:58
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.




Source Code

/**
 * Defines an interface for encapsulating the behavior associated with a
 * particular state of the Context.
 * 
 * @role __State
 */
public interface State {
        void handle(String sample);}

/**
 * Defines an interface of interest to clients. Maintains an instance of a
 * ConcreteState subclass that defines the current state.
 */
public class Context {
        private State state;        public void setState(State newState) {
                this.state = newState;        }

        public void someOperation() {
                state.handle("aaa");        }

}

/**
 * Implements a behavior associated with a state of the Context.
 */
public class ConcreteState implements State {
        public void handle(String sample) {
                /* put your code for this particular state here */
        }

}

/pre>

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close


Powered By Joomla Tags

Last Updated ( Friday, 17 June 2005 23:40 )
 


Another articles:


Content View Hits : 2726354

Enter Amount: