The pattern https://en.wikipedia.org/wiki/State_pattern requires two classes:
- The context class, which handles events and takes actions, and
- The state class, an instance of which is owned by the context. The state class has an abstract base, and is derived for each actual state.
Since CTRL++ requires a class to be fully declared before it can be referenced, this cannot be implemented, as far as I can see.
Even 'cheating' mechanisms, such as having the State class's methods return the string name of a static function in the context class fail to work:
Code: Select all
// Example concrete state class
class Damper_Closing_State: Damper_Base_State
{
public string onOpenCmd() { return "startOpening"; }
// ...
};
class Damper_Context
{
shared_ptr<Damper_Base_State> _state; // Contains shared_ptr instance of concrete state class
private call(string methodName) {
// ************************ Attempt to call a static function fails to resolve!
callFunction("Damper_Context::" + methodName, this);
}
public static void startOpening(Damper_Context self) {
}
}