正在加载图片...
$20.3 A FUNCTIONAL,TOP-DOWN SOLUTION 679 mathematical sense;at the software level we can choose to implement transition either by a function in the software sense(a routine returning a value)or by a data structure such as an array.For the moment we can afford to postpone the choice between these solutions and just rely on transition as an abstract notion. In addition to the function transition we also need to designate one of the states,say state initial,as the place where all sessions start,and to designate one or more states as final through a boolean-valued function is final.Again this is a function in the mathematical sense,regardless of its eventual implementation. We can picture the transition function in tabular form,with rows representing states and columns representing choices,as shown below. Conventions used in this table:there is just one Help state,0,with a special transition Return which goes back to the state from which Help was reached,and just one final state, -1.These conventions will not be necessary for the rest of the discussion but help keep the table simple. A transition Choice→ 0 2 3 table ↓State 1(Initial) -1 0 5 2 2(Flights) 0 1 3 3(Seats) 0 2 4(Reserv.) 0 3 5(Confirm) 0 4 1 (Help) Return -1(Final) The routine architecture Following the traditional precepts of top-down decomposition,we choose a "top"(the main program)for our system.This should clearly be the routine execute session that describes how to execute a complete interactive session.§20.3 A FUNCTIONAL, TOP-DOWN SOLUTION 679 mathematical sense; at the software level we can choose to implement transition either by a function in the software sense (a routine returning a value) or by a data structure such as an array. For the moment we can afford to postpone the choice between these solutions and just rely on transition as an abstract notion. In addition to the function transition we also need to designate one of the states, say state initial, as the place where all sessions start, and to designate one or more states as final through a boolean-valued function is_ final. Again this is a function in the mathematical sense, regardless of its eventual implementation. We can picture the transition function in tabular form, with rows representing states and columns representing choices, as shown below. Conventions used in this table: there is just one Help state, 0, with a special transition Return which goes back to the state from which Help was reached, and just one final state, –1. These conventions will not be necessary for the rest of the discussion but help keep the table simple. The routine architecture Following the traditional precepts of top-down decomposition, we choose a “top” (the main program) for our system. This should clearly be the routine execute_session that describes how to execute a complete interactive session. Choice → ↓ State 0 1 2 3 1 (Initial) –1 0 5 2 2 (Flights) 0 1 3 3 (Seats) 0 2 4 4 (Reserv.) 0 3 5 5 (Confirm) 0 4 1 0 (Help) Return –1 (Final) A transition table
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有