Quantcast
Viewing all articles
Browse latest Browse all 25

Design Patterns Uncovered: The State Pattern

Image may be NSFW.
Clik here to view.
Today’s pattern is the State pattern, which allows objects to behave in different ways depending on internal state. State is used when you need a class to behave differently, such as performing slightly different computations, based on some arguments passed through to the class.State in the Real World Vending machines maintain an internal state which allow it to change it’s behaviour accordingly. For example, if there is no change available, it will demand exact change. When something is out of stock, i...

Viewing all articles
Browse latest Browse all 25

Trending Articles