Print at Dec 20, 2025, 12:02:34 AM View all posts in this thread on one page
Posted by Cardinal at Jul 26, 2011, 8:22:54 AM
A quick question about ControllerState subclasses
Hello,

Why do some subclasses of ControllerState override setState? Isn't it the same everywhere? (escape() then assign a state)? I don't get it.

Thanks for any help smile

Posted by Puybaret at Jul 26, 2011, 9:52:03 AM
Re: A quick question about ControllerState subclasses
setState in PlanController class isn't overridden. It's only used in ControllerState when the state needs to be changed. See State design pattern and UML state machine diagram.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Cardinal at Jul 27, 2011, 8:06:32 AM
Re: A quick question about ControllerState subclasses
Sorry I meant setMode() not setState().

Posted by Cardinal at Jul 27, 2011, 9:51:48 AM
Re: A quick question about ControllerState subclasses
Is it because you want to prevent self-transitions in some states in order to avoid exit() and enter() from running while the state did not actually change?

On a side note, setMode() in the ControllerState hierarchy is a bit confusing. The argument of the method (mode) is not being retained by the invoker, rather, an assignment is happening at the outer Class level. Thus, It's semantically incorrect to give this method a Setter naming style. A better name would have been switchMode or something to that effect. Correct me if I'm wrong.

Posted by Puybaret at Aug 7, 2011, 12:49:54 PM
Re: A quick question about ControllerState subclasses
I guess I wanted to let a state controls what should be done when the user changes current mode.

On a side note, setMode() in the ControllerState hierarchy is a bit confusing. [...]
You're probably right, but I don't believe a lot of programmers are aware of the reason you mentioned... wink
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator