Book a Demo

Author Topic: How to define the set of states valid for class  (Read 3327 times)

JoGo

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
How to define the set of states valid for class
« on: August 26, 2008, 08:43:16 pm »
Hi,  I'm building a system where the underlying architectural philosophy is that at any given time, an object is in a defined state, and from each defined states, certain transitions are permissable to other states.  So for example, a Car object can be either in state Idling, Moving or Stopped.  Now its easy enhough to create a Car object in EA. and easy enough to create 3 state [or should it be state machine?] objects.  But how can I indicate that the states are the possible states of a car object?

i'd like to do this in quite a "hard" way, such that it would only be possible to define state transitions betweens states belonging to the same object.  Conversely, it would not be possible to define a transition between a state belonging to one object, and a state belonging to another object.  

How is this implented in EA - or is it not at all and I'm missing the point somehow ...

Cheers,

JG

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: How to define the set of states valid for clas
« Reply #1 on: August 26, 2008, 10:01:45 pm »
In the project browser, a class has a context menu "Add - State Machine" which creates a state machine below the class, and below that a state machine diagram.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to define the set of states valid for clas
« Reply #2 on: August 26, 2008, 10:57:21 pm »
You can also do this from a diagram. Select the class and right-click on it. Choose Add from the context menu and you should see the option Frank mentions on the second-level context menu.
No, you can't have it!

JoGo

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: How to define the set of states valid for clas
« Reply #3 on: August 27, 2008, 11:38:54 am »
thanks for your replies.  I've done this, and also embedded the state diagrams in the parent class diagram, and it's definitely a step in teh right direction.  

I'm not sure if the state really "belongs" to my class [i.e. could not have a transition between state in one class to state in another class], but I'll play with it for a while.  

Thanks!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to define the set of states valid for clas
« Reply #4 on: August 27, 2008, 10:27:35 pm »
Here's my 0.02 CAD for what it's worth...

You'll have to think this out a bit. Perhaps the state model should be on its own, or belong to a common parent.

A good rule of thumb is that if you are describing the states that (an instance of) your class could go through in its life cycle, then embedding the diagram seems appropriate. If the state model seems more of a system thing, then perhaps a higher level or an independent diagram would be better. In the second case, make sure you are not describing something else that would be better modeled with a different diagram (composite structure, collaboration, whatever).

You might also embed a state diagram to illustrate a use case - some use cases lend themselves to state models, but most seem to be better described in other paradigms. In this case you should consider creating the use case involved and putting the state model below that. You might use a trace or realize link to show the relationship between the diagrams.

David
No, you can't have it!