Re-usable Guards for State Transitions

While working on a state machine in a model earlier this week and ran across a situation where i had a complex set of guard conditions associated with a state transition. But then I also realized that this same set of guards was going to be used elsewhere in the same state machine.  Using Cameo 19 SP4, is there a way to capture guard expressions so that they can be re-used and applied to multiple transitions?

Thank you,

Chandan

  • Chandon,

    Lacking insight into your organization's model standards and conventions (yes, I think this case should be documented there), I'll suggest you consider modeling a Constraint (std, not a constraint block) using OCL and linking your recurring state machine Guards to the Constraint. Hopefully your tooling supports model simulation when using OCL for this purpose.

    Regards,
    Geoff
  • In reply to Geoffrey Shuebrook:

    Hi Geoff, thanks for the suggestion.  I tried this and I am able to point a transition to a constraint (owned by the state machine's classifier), but that creates a copy of the original constraint under the transition. 

    If i am interpreting UML spec correctly (v2.5.1, section 14.2.2), it appears that a guard (as constraint) can be owned by up to one transition, so the language may not support the exact feature I'm looking for.

    Respectfully,

    Chandan

  • In reply to Chandan Mathur:

    I forgot to mention - I can drag/drop a constraint onto a transition and that will create a constraint on the transition, but that constraint is not set as the guard.
  • In reply to Chandan Mathur:

    Chandon,

    Apologies.

    Re: UML v2.5.1, section 14.2.2 (not being argumentative) as I read the Abstract Specification of a Transition, a Transition may have an optional property named "guard" which is of type Constraint, which is further constrained to a single Constraint specification if present (multiplicity = 0..1). I make no claim to being a UML expert and may interpretation is based solely on my independent study of the language. I may be wrong. This is my understanding and I do not intend to argue the point, but I am willing to correct my understanding with inout from an expert.

    I played around with CSM 19.4 this morning trying both OCL for the Guard and an "Opaque Expression". While I still believe that the Constraint model element is appropriate, I concur the behavior of the tool may be a suboptimal solution.

    Another approach: Consider specifying your complex Guard expression in the form of an Opaque Expression. In my experimentation, I created a separate package containing the named opaque expression ( I named the expression as the hyperlinking dialog lists model elements by their name). Then from the specification of the Transition's Guard property, I hyperlinked to the Body ("Representation Text") of the Named Opaque Expression. I did this for multiple transitions of the State Machine. Further I made a change to the Opaque Expression and the change was reflected in the Guard of all the linked Transitions.

    If this isn't the solution your desire, I apologize. Best of Luck.

    Regards,
    Geoff
  • In reply to Geoffrey Shuebrook:

    Geoff, very much appreciate your advice and thanks for your suggestion on the opaque expression...I will give that a try. I think that will meet my needs.

    Respectfully,

    Chandan
Related