正在加载图片...
$20.5 AN OBJECT-ORIENTED ARCHITECTURE 685 The notion of state was important in the original problem statement,but in the functional architecture that importance was lost:the state was just represented by a variable,passed from routine to routine as if it were some kind of lowlife.We have seen how it avenged itself.Now we are ready to give it the status it deserves.STATE should be a class,one of the principals in the structure of our new object-oriented system. In that class we will find all the operations that characterize a state:displaying the corresponding screen (display),analyzing a user's answer (read),checking the answer (correct),producing an error message for an incorrect answer (message),processing a correct answer(process).We must also include execute state,expressing the sequence of actions to be performed whenever the session reaches a given state;since the original name would be over-qualifying in a class called STATE,we can replace it by just execute. Starting from the original top-down functional decomposition picture,we can highlight the set of routines that should be handed over to STATE: STATE features execute session Level3 initial transition execute is_final Level2 state STATE Level 1 display read correct message process The class will have the following form: ..class STATE feature input:ANSWER choice:INTEGER execute is do...end display is .. read is... correct:BOOLEAN is .. message is .. process is .. end§20.5 AN OBJECT-ORIENTED ARCHITECTURE 685 The notion of state was important in the original problem statement, but in the functional architecture that importance was lost: the state was just represented by a variable, passed from routine to routine as if it were some kind of lowlife. We have seen how it avenged itself. Now we are ready to give it the status it deserves. STATE should be a class, one of the principals in the structure of our new object-oriented system. In that class we will find all the operations that characterize a state: displaying the corresponding screen (display), analyzing a user’s answer (read), checking the answer (correct), producing an error message for an incorrect answer (message), processing a correct answer (process). We must also include execute_state, expressing the sequence of actions to be performed whenever the session reaches a given state; since the original name would be over-qualifying in a class called STATE, we can replace it by just execute. Starting from the original top-down functional decomposition picture, we can highlight the set of routines that should be handed over to STATE: The class will have the following form: … class STATE feature input: ANSWER choice: INTEGER execute is do … end display is … read is … correct: BOOLEAN is … message is … process is … end STATE features execute_session initial transition execute_ state is_final display read correct message process Level 1 Level 3 Level 2 STATE
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有