Select Page

State

State

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>

About The Author

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories