[State Design Pattern] How to manage concurrent (or parallel) states.

This is a discussion on [State Design Pattern] How to manage concurrent (or parallel) states. within the Object forums in Theory and Concepts category; Hello, I'm trying to make a model of a program behaviour. I want to use an UML state diagram and the State design pattern. The program can be in one of these states: - Stopped - Running - Paused - Safe Independently of these states, the program can be in these two other states: - Local - Remote Moreover, the states Local and Remote are nonsense in the Stopped state. I didn't get all possibilities of the UML state diagram tools. However I did these two diagrams which are not correlated : http://www.developpez.net/forums/att...3&d=1218461391 and http://www.developpez.net/forums/att...4&d=1218461408 - How can I join ...

Go Back   Application Development Forum > Theory and Concepts > Object

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-11-2008, 11:32 AM
Damien.Garrido
Guest
 
Default [State Design Pattern] How to manage concurrent (or parallel) states.

Hello,

I'm trying to make a model of a program behaviour.

I want to use an UML state diagram and the State design pattern.

The program can be in one of these states:
- Stopped
- Running
- Paused
- Safe

Independently of these states, the program can be in these two other
states:
- Local
- Remote

Moreover, the states Local and Remote are nonsense in the Stopped
state.

I didn't get all possibilities of the UML state diagram tools. However
I did these two diagrams which are not correlated :
http://www.developpez.net/forums/att...3&d=1218461391
and
http://www.developpez.net/forums/att...4&d=1218461408

- How can I join these two diagrams ?
- Do you think I can use one finite state machine to represent those
concurrent states ?
- Should I use regions and/or submachine states ?
- How can I represent this in a UML diagram and/or how to translate it
using the State design pattern ?

Any help would be appreciated.

Many thanks,

Damien
Reply With Quote
  #2  
Old 08-11-2008, 01:15 PM
Ed Prochak
Guest
 
Default Re: How to manage concurrent (or parallel) states.

On Aug 11, 10:32 am, "Damien.Garrido" <damien.garrido.w...@gmail.com>
wrote:
> Hello,
>
> I'm trying to make a model of a program behaviour.
>
> I want to use an UML state diagram and the State design pattern.
>
> The program can be in one of these states:
> - Stopped
> - Running
> - Paused
> - Safe
>
> Independently of these states, the program can be in these two other
> states:
> - Local
> - Remote
>
> Moreover, the states Local and Remote are nonsense in the Stopped
> state.
>
> I didn't get all possibilities of the UML state diagram tools. However
> I did these two diagrams which are not correlated :http://www.developpez.net/forums/att...entid=34463&d=...
> andhttp://www.developpez.net/forums/attachment.php?attachmentid=34464&d=...
>
> - How can I join these two diagrams ?
> - Do you think I can use one finite state machine to represent those
> concurrent states ?
> - Should I use regions and/or submachine states ?
> - How can I represent this in a UML diagram and/or how to translate it
> using the State design pattern ?
>
> Any help would be appreciated.
>
> Many thanks,
>
> Damien


Sorry, your diagrams are password protected. What little French I
learned in High school has left me long ago, so I don't think signing
up would help me much.

Suggestion: try to describe the transitions in words. For example from
stopped what states are possible? Are both Running/local and running/
remote possible?

HTH,
ed
Reply With Quote
  #3  
Old 08-11-2008, 03:01 PM
H. S. Lahman
Guest
 
Default Re: [State Design Pattern] How to manage concurrent (or parallel)states.

Responding to Damien.Garrido...

Since you posted to comp.object, I assume you are looking for OOA/D
perspective.

I had the same access problem as Prochak. However, a lack of facts
should never stand in the way of an opinion...


> I'm trying to make a model of a program behaviour.
>
> I want to use an UML state diagram and the State design pattern.


IMO, the GoF State pattern is misnamed; it should be called Role. It is
really best suited for migration through multiple roles where each role
has multiple behavior responsibilities.

If one tries to use it as a state machine it tends to lead to code bloat
because one needs a separate class and object for each state. It also
has the problem (at least for Moore models) that there is only one
behavior for the object and no knowledge, which raises the specter of
functions as first class objects.

The code will be much simpler if one just makes the state actions simple
methods and employs a static STT as a jump table to get to the right
action based on indexing by {current state, event ID}.

> The program can be in one of these states:
> - Stopped
> - Running
> - Paused
> - Safe


Could you put some words around the semantics of Safe? With my
preconceived notion of the context I am a little concerned that Safe may
be orthogonal to at least some of the other states. Was it intended to
be a superstate?

> Independently of these states, the program can be in these two other
> states:
> - Local
> - Remote


My gut feeling is that this would not be a state machine at all. These
states seem like something one could represent with values of a state
variable (object attribute). That is, when doing something else like
constructing messages one needs to know whether these conditions
prevail, but I would be surprised if they had an intrinsic behavior.

So you need to put some words around what behavior the state actions
might have and how that maps to the overall problem context. (I'll
assume below that they really do have behavior.)

>
> Moreover, the states Local and Remote are nonsense in the Stopped
> state.
>
> I didn't get all possibilities of the UML state diagram tools. However
> I did these two diagrams which are not correlated :
> http://www.developpez.net/forums/att...3&d=1218461391
> and
> http://www.developpez.net/forums/att...4&d=1218461408
>
> - How can I join these two diagrams ?


Do you really want to join them? I would expect these two state machines
to describe behaviors in different objects. It is not even clear to me
that there would be direct collaborations between them.

In fact, it would not surprise me if the objects were in different
subsystems. For example, local vs. remote seems like a view of a program
in a low level service subsystem where one was dealing with context
around interprocess communications (e.g., acquiring sockets and
whatnot). Meanwhile the other states seem like a view of a program
appropriate for a high level controller for execution of the program itself.

> - Do you think I can use one finite state machine to represent those
> concurrent states ?


My offhand reaction, based solely on my interpretation of the state
names, would be No. A state represents a condition of being of an entity
and only one condition at a time should prevail. Thus two states can
only prevail concurrently if the entities are different (e.g., different
objects). As you indicate, the states in the two models seems orthogonal
so I would expect them to represent different objects' state machines.

OTOH, people who use Harel state machines seem comfortable with the
notion of superstates coexisting with substates. [Personally, I feel
that if an object's behavior is so complex that one is even tempted to
use a Harel model there is a serious problem with cohesion and one
should look to break up the object via delegation. So I won't go there
and someone else can respond with a Harel solution. B-)]

> - Should I use regions and/or submachine states ?


Anything is possible. B-) However, I've been doing object state machines
for a couple of decades and I've never needed them.

> - How can I represent this in a UML diagram and/or how to translate it
> using the State design pattern ?


I think the representation would be spread over multiple objects and UML
diagrams. But that really depends on what the overall problem is.

I wouldn't use the State pattern at OOP time for the reasons above, but
if one does that, the transformation from a UML OOA/D model is pretty
straight forward. Essentially each state machine state gets its own
subclass of [State] and the relationship between [Context] and [State]
is instantiated based on the {event ID, current state} from an STT. If
one does Harel-like things, one has additional associations between the
super- and substates that are hard-wired.


--
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@pathfindermda.com
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info@pathfindermda.com for your copy.
Pathfinder is hiring:
http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH
Reply With Quote
  #4  
Old 08-12-2008, 06:22 AM
S Perryman
Guest
 
Default Re: [State Design Pattern] How to manage concurrent (or parallel) states.

"Damien.Garrido" <damien.garrido.work@gmail.com> wrote in message
news:01f788f0-b5eb-4320-85b4-8c177cd58709@56g2000hsm.googlegroups.com...

> I'm trying to make a model of a program behaviour.


> I want to use an UML state diagram and the State design pattern.


> The program can be in one of these states:
> - Stopped
> - Running
> - Paused
> - Safe


> Independently of these states, the program can be in these two other
> states:
> - Local
> - Remote


> Moreover, the states Local and Remote are nonsense in the Stopped state.
> - How can I join these two diagrams ?
> - Do you think I can use one finite state machine to represent those
> concurrent states ?
> - Should I use regions and/or submachine states ?
> - How can I represent this in a UML diagram


1. Firstly, orthogonal state machines means the cartesian product of the
individual states. Which gives 4 x 2 = 8 overall states.

2. Because you claim that (Stopped,Local) and (Stopped,Remote) are
meaningless, you don't have the pre-requisites for #1.

So if you proceed down this path, you need to have the following :

Main = Stopped | Not Stopped (think of a better name)

Not Stopped = (S1,S2)
S1 = Running | Paused | Safe
S2 = Local | Remote


> and/or how to translate it using the State design pattern ?


S1 and S2 are State pattern impls in their own right.
The Not Stopped state creates instances of each, when it is created.

The next thing is to configure the event flow thru the FSM.
All events (external or internal) will be delivered to S1/S2 via
the Not Stopped instance.


Regards,
Steven Perryman


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:58 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.