The state pattern is a similar to the command pattern, but the intent is quite different.
状态模式类似于命令模式,但是意图截然不同。
Now look at Listing 8, which has the same logic for handling the robot's states, but this time puts the logic into the state pattern.
现在查看清单8,其中提供了相同的逻辑处理机器人的状态,但是这一次把逻辑放入状态模式。
For instance, with slight modification you can introduce the state pattern with some persistence to keep track of conversational state.
例如,只需稍作修改,就可以为state模式引入持久性,以跟踪会话状态。
One of the benefits of applying the state pattern is that it can resolve the if-statement situation difficulty shown in Figure 3 by isolating the various states.
使用State这个模式的一个好处是,它可以通过孤立各种状态来分解图3中if语句的情景。
You now have the best of both worlds: you are leveraging the navigational state pattern defined via the JSR 286 public render parameters and you can easily set parameters on a specific URL.
现在两全其美了:您可以利用JSR 286公共呈现参数定义的导航状态模式,并且您也可以轻松地在一个指定url中设置参数。
Figure 6: State pattern and participating classes within the RSA pattern explorer.
图6:state模式和RSA模式浏览器中参与的类。
Figure 6: State pattern and participating classes within the RSA pattern explorer.
图6:state模式和RSA模式浏览器中参与的类。
应用推荐