当前位置:首页 > Student - Answers - Chapter - 06
Suggested answer for Exercise 6.7
A modified statechart is shown below. A `cancel' event received when the reservation is in the `Seated' state causes a transition to the new `Error' state. An additional event, here labelled `reset', is needed to get the reservation back into the `Seated' state.
It could be argued that in this particular case, the error is simply a case of operator error, rather than the reservation object itself
entering an illegal state. After all, it is unlikely that the reservation itself will change in any way if an attempt is made to cancel it. An alternative way of specifying error handling behaviour in this case might therefore be simply to specify it using an action, as shown below.
Suggested answer for Exercise 6.8
The most important thing to consider when deciding whether a statechart is necessary for a particular class is whether the instances of the class exhibit any state-dependent behaviour. In terms of the actual running of the restaurant, there is clearly a major different between a table which is currently empty and one which is occupied, and this gives a certain plausibility to Figure 6.8.
However, as far as the booking system is concerned, the difference is invisible: there are currently no messages in the system whose effect depends on whether a table is empty or occupied, and no messages which would cause a table object to move from one state to the other. There is therefore no point in drawing a statechart for the Table class, at least with the current state of the system requirements.
共分享92篇相关文档