tags:

views:

89

answers:

1

I have a Contract class. The contract is valid 1 Jan 2010 - 31 Dec 2010.

It can be in state Active or Passive, depending on which date I ask the instance for it's state. ex. if I ask 4 July 2010, it's in state Active, but if I ask 1 Jan 2011, it's in state Passive.

Statemachine diagram:

From Start state, which state should it go to next ? I'm thinking a pseudo state "default" with an entry function deciding which state to go to next, and then a substate machine with Active and Passive, and then an End state on removal.

But this seems to complicated for such a trivial problem.

How would you do it ?

A: 

Hmm, you want either do what you describe, which will allow the Contract to be in invalid (start/end) state when someone tries to use the contact without prior date event, or you can try to add the call to that function in a constructor, so your contract is in proper state right away. There might be other solutions, but you should think about what other events (messages/method calls) can happen on the contract than the date. Some might affect the stae as well. BTW. your solution is not as complicated when you instead of embedding the state machine only connects the start and end to active and passive states.

Gabriel Ščerbák
Your suggestion would mean that I have one "created state" (black dot), and 2 arrows leading out from that created state, one to Active and one to Passive (depending on what state I inject in the contructor) !?
@hjo1620 you can have only one transition from initial state, but you can use the choice element.
Gabriel Ščerbák
I was assuming that you could only have one initial state, but in Jude/Astah you can do it with the tool. Is it bad tool support of the language or do you know of a normative reference in the UML spec somewhere ?
@hjo1620 there can be only one initial state for a region: UML Superstructure, p549, ch15.3.10 Region, paragraph Constraints, item [1]... I would use the choice.
Gabriel Ščerbák
Thanks for answering my question.