状态模式
2016-12-03 20:27:11 0 举报
状态模式是一种行为设计模式,允许对象在其内部状态改变时改变其行为。这种模式将对象的状态封装在独立的类中,并使用一个共同的接口来管理这些状态对象。当对象的状态发生变化时,它会选择相应的状态对象,并通过该状态对象的接口来执行相应的操作。 状态模式的主要优点是将状态与行为分离,提高了代码的可维护性和可扩展性。此外,它还允许客户端代码以一种通用的方式来处理对象的状态变化,而无需关心具体的状态实现细节。然而,状态模式的缺点是可能会增加系统的复杂性,因为需要维护多个状态对象和它们之间的转换逻辑。
作者其他创作
大纲/内容
MiddleState
+ MiddleState(AccountState state)+ writeNote(int score) : void+ downloadFile(int score) : void + checkState(int score) : void
HighState
+ HighState(AccountState state)+ writeNote(int score) : void+ downloadFile(int score) : void + checkState(int score) : void
AccountState
# acc : Account# point : int# stateName : String
+ checkState(int score) : void+ downloadFile(int score) : void+ writeNote(int score) : void+ replyNote(int score) : void+ setPoint(int point) : void+ getPoint() : int+ setStateName(String stateName) : void+ getStateName() : String
state
PrimaryState
+ PrimaryState(AccountState state)+ writeNote(int score) : void+ downloadFile(int score) : void + checkState(int score) : void
Account
- state : AccountState- name : String
+ Account(String name) : void+ setState(AccountState state) : void+ AccountState getState() : void+ setName(String name) : void+ getName() : String+ downloadFile(int score) : void + writeNote(int score) : void+ replyNote(int score) : void
acc
0 条评论
下一页