State Design Pattern by Example
State pattern falls under the category of Behavioral patterns. State design pattern comes in picture when a system’s behavior is depends on its own state or some other resource’s state. If an implementation is depends on the states, we end up with snarl of conditional statement every where in code. A very neat approach to deal with such situation is to separate out every state’s behavior and use them where ever they are applicable. The state pattern allows an object to alter its behavior when is internal state changes . The object is appeared to change its class. State pattern is a way to implement the same. Class Diagram : As above class diagram shows, System class holds state instance. As state of system changes , all handle request delegated to respective State’s concrete implementation. Example : Have an example of Vending machine. Vending machine has following states No Coin Inserted Coin Inserted Dispensing Empty Following diagram explain behavior...
good. all info in one place :)
ReplyDeleteIf you find any conflict then lets update the post :)
ReplyDeleteHi Yogesh.
ReplyDeleteThanks to your post I finally could load a resource stylesheet for my application: I spent more than 4 hours googling everywhere and not finding the right answer.
My mistake was that I wrote:
this.getClass().getResourceAsStream("stylesheet.xsl")
But my file was located in WEB-INF/classes.
Thanks to your post I changed to "/stylesheet.xsl" and now everything works fine.
Thanks again!
@Frederic F. MONFILS You always Welcome :)
ReplyDeleteLife saver! Saved me a couple of hours as well.
ReplyDelete