A quick question about ControllerState subclasses

This topic has been viewed 3405 times and has 4 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
Cardinal
Posts: 22
Joined: Mon Jul 04, 2011 2:46 pm

A quick question about ControllerState subclasses

Post by Cardinal »

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 [:)]
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: A quick question about ControllerState subclasses

Post by Puybaret »

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
Cardinal
Posts: 22
Joined: Mon Jul 04, 2011 2:46 pm

Re: A quick question about ControllerState subclasses

Post by Cardinal »

Sorry I meant setMode() not setState().
Cardinal
Posts: 22
Joined: Mon Jul 04, 2011 2:46 pm

Re: A quick question about ControllerState subclasses

Post by Cardinal »

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.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: A quick question about ControllerState subclasses

Post by Puybaret »

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... [;)]
Emmanuel Puybaret, Sweet Home 3D creator
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest