-
Book Overview & Buying
-
Table Of Contents
Scala Design Patterns
By :
The state design pattern is really similar to the strategy design pattern we looked at in the previous chapter. Its purpose is to:
Allow us to choose a different behavior of an object based on the object's internal state.
Basically, the difference between the state design pattern and the strategy design pattern comes from the following two points:
The strategy design pattern is about how an action is performed. It is usually an algorithm that produces the same results as other algorithms.
The state design pattern is about what action is performed. Depending on the state, an object could be doing different things.
Implementing the state design pattern also closely resembles the implementation of the strategy design pattern.
Imagine a media player. Most media players have a play button—when we activate it, it usually changes its appearance and becomes a pause button. Clicking the pause button now also does something different—it pauses the playback and reverts...
Change the font size
Change margin width
Change background colour