`

Head first design pattern(State pattern)

UP 
阅读更多
[u][/u]I read the State pattern in the Head first design pattern a few days ago,At the present,i will just sum it up.

   Without state pattern,we just use "if-else" controlling construct to treat with the change of the object state,as this,the coupling is very high,when the requirment changes,  we  will  have to change a lot of code.Fortunately,we could use the state pattern to low the coupling.

   Here is the offical defination,the state pattern allows an object to alter its behavior when its internal state changes.it use a state object to encapsulate the object's behavior.the state pattern encapsulate the altering parts to seperate the steady parts with them.
this pattern need state object to alter its behavior.the state object konw how to change to another state,what'more ,the state object contains the behavior with the state,so we can use the polymorphism to
change the behavior dynamicly
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics