[statechart] using the same event handler in multiple states.
I'm trying to implement a state machine using the boost statechart library. It has 3 main states (call them "State 1", "State 2", and "State 3") and 3 classes of events ("Class 1", "Class 2", and "Class 3"). State 1 should have event handlers for all Class 1 events. State 2 should have handlers for Class 1 and 2 events. State 3 should have handlers for Class 1, 2, and 3 events. The handling of each class of events is essentially the same regardless of what state the machine is in. Is there a way I can derive State 3 from States 1 and 2 so that I'm not repeating the Class 1 and 2 event handling code in State 3? What is the best way to architect something like this? Thanks, PaulH
Hi Paul
I'm trying to implement a state machine using the boost statechart library. It has 3 main states (call them "State 1", "State 2", and "State 3") and 3 classes of events ("Class 1", "Class 2", and "Class 3"). State 1 should have event handlers for all Class 1 events. State 2 should have handlers for Class 1 and 2 events. State 3 should have handlers for Class 1, 2, and 3 events.
The handling of each class of events is essentially the same regardless of what state the machine is in.
It sounds like you should put state 2 & state 3 in an outer state A. Then put state A and State 1 into an outer state B. Let state B handle class 1 events and let state A handle class 2 events. Finally, let state 3 handle class 3 events. HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
In my opinion it would be better to repeat the code if you have to in order to reduce the dependencies between the classes. -----Original Message----- From: boost-users-bounces@lists.boost.org on behalf of Paul Heil Sent: Mon 4/28/2008 10:33 AM To: boost-users@lists.boost.org Subject: [Boost-users] [statechart] using the same event handler in multiplestates. I'm trying to implement a state machine using the boost statechart library. It has 3 main states (call them "State 1", "State 2", and "State 3") and 3 classes of events ("Class 1", "Class 2", and "Class 3"). State 1 should have event handlers for all Class 1 events. State 2 should have handlers for Class 1 and 2 events. State 3 should have handlers for Class 1, 2, and 3 events. The handling of each class of events is essentially the same regardless of what state the machine is in. Is there a way I can derive State 3 from States 1 and 2 so that I'm not repeating the Class 1 and 2 event handling code in State 3? What is the best way to architect something like this? Thanks, PaulH
"Shutters, Zachary A"
In my opinion it would be better to repeat the code if you have to in order to reduce the dependencies between the classes.
What dependencies? Even if there are more dependencies, why make maintenance harder by duplicating information? Regards, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (3)
-
Andreas Huber
-
Paul Heil
-
Shutters, Zachary A