Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: a State machine with Roles - possible? (class or instance)

by salva (Canon)
on May 30, 2013 at 15:48 UTC ( [id://1036086]=note: print w/replies, xml ) Need Help??


in reply to Re^4: a State machine with Roles - possible? (class or instance)
in thread a State machine with Roles - possible?

then i think we could implement complex State machines with multidimensional states.

Well, actually, just a small subset. Those whose response to an event may only depend on one dimension of the state. Let's call them linear multidimensional state-machines. Those are pretty uninteresting, and can be simulated easily by an aggregation of unidimensional state-machines.

In practice, you will find that there are interactions between the state dimensions and so, in order to model the responses to the different events that may array you will have to take into consideration several dimensions. In other words, behavior can be modeled as a multidimensional matrix of responses.

My experience is that when one gets to the point of needing a multi-dimensional non-linear state machines to solve some problem* it just means that he is doing something wrong and needs to get back and try to break the problem in simpler ones.

*) unless there is some kind of code generator doing it!

  • Comment on Re^5: a State machine with Roles - possible? (class or instance)

Replies are listed 'Best First'.
Re^6: a State machine with Roles - possible? (class or instance)
by mascip (Pilgrim) on May 31, 2013 at 16:58 UTC

    Thank you Salva, i think that's a very good point: if you need to do this, you probably need to redesign.

    I think your first point is wrong though: you can have "non-linear" behavior, for example a "Person" turned into a "Zombie", could become stronger when they are "Poisoned" (instead of becoming weaker like a non-Zombie person).

    And transitions can be implemented in the Roles, so that you can also have complex transitions.

    So, i think you'd get a truly multidimensional State Machine (is that right, or did i misunderstand something?). It might just get a bit messy in terms of the code, which shows you might want to redesign.

    It's still nice to know that it's possible though. In the meantime i'll try and use Class::StateMachine.

      I think your first point is wrong though: you can have "non-linear" behavior, for example a "Person" turned into a "Zombie", could become stronger when they are "Poisoned" (instead of becoming weaker like a non-Zombie person).

      You are right in the sense that it can be done. But my point is that you loose the advantages of considering the state as multidimensional.

      For me, the real issue with complex state machines (mutidimensional or not) is not how to implement them but how to express them in a way that is easy to understand for humans. How to avoid ending with a big ball of code.

        I agree with you, that an intuitive API is the more important than implementation.

        But do you have a real world example of a multidimensional state machine?

        This "door" thing is just to shallow to justify the efforts and clarify advantages of different approaches.

        Cheers Rolf

        ( addicted to the Perl Programming Language)

        And that's where Class::StateMachine::Declarative shines: it's concise, and makes it easy for humans to apprehend the whole transitions set.

        I realise now that objects, if they have several attributes, ARE multidimensional state machines anyway. My question was thus mostly about whether it is possible to unapply a Role; thinking that it could be useful some day.

        Just one last quesiton: Is it possible to use Class::StateMachine in a Role?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1036086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found