Posts

Showing posts with the label State Pattern

Design Patterns Series 15 - State Pattern

This Post will be about The State Pattern where an object keeps track of its internal state, and can change its behavior based on that state. The State Pattern : The State Design Pattern will " Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. " In other words your code should keep track of an internal state. Any part of the code can check what the current state is and react accordingly. When you use the State Pattern , any part of your code can check what state is current. That clarify and centralize the workings of very large pieces of code because you have control over what far-flung code segments do, just by changing the current state. In general, The State Pattern is useful when you have got a lot of code that's getting more and more murky and complex. If you can compartmentalize the working of what you are trying to do into a set of independent states, you can compartmentalize your code. ...