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 [:)]
A quick question about ControllerState subclasses
This topic has been viewed 3403 times and has 4 replies
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
Re: A quick question about ControllerState subclasses
Sorry I meant setMode() not setState().
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.
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.
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.
You're probably right, but I don't believe a lot of programmers are aware of the reason you mentioned... [;)]On a side note, setMode() in the ControllerState hierarchy is a bit confusing. [...]
Emmanuel Puybaret, Sweet Home 3D creator
Who is online
Users browsing this forum: No registered users and 1 guest