A Conditional Structured Activity Node is the modeling equivalent of an 'If-Then-Else' programming construct. At its simplest, it consists of a Clause containing:
- A Test partition that evaluates a condition, and
- A Body partition that performs one or more actions if the Test condition is satisfied
You can have more than one Clause, so that if the Test condition is not satisfied its Body is ignored and processing moves to the next Clause and evaluates another Test condition.
Each Clause has a 'Decider' ActionPin to hold the result of the Test, and a 'Body Output' ActionPin to hold the result of the Body's actions (if executed). The Conditional Node itself has a result ActionPin that makes available the overall result of the Node (the output of the first Body to be executed).
The representation of a Conditional Node on an Activity diagram resembles this:
You define Conditional Nodes by dragging other Activity diagram elements from the Toolbox page into the appropriate partition of the element, and linking and organizing the structure as required. The elements are aligned on the top left of the partition, so that resizing the node maintains the organization of the structure within and between the partitions. If you try to shrink the node below the structure size, the node automatically defaults to the 'best fit' size.
When you create a Conditional Node, the 'Properties' dialog displays. Much of this you can complete as for any other element. However, for the Conditional Node you also display the Properties window, which has an additional 'Condition' tab.
On this tab, in the 'Result' panel, add an Action Pin to hold the result for the node, clicking on theto display the 'Select Pins' dialog.
A Conditional Node automatically contains one Clause containing a Test partition and a Body partition, and a Decider Pin and Body Output Pin. You can add further Clauses as required. For each Clause you add an Action Pin for the Decider and for the Body Output. Click on theto save the Clause definition.
The 'Select Pin' dialog reveals only Output pins as appropriate to the context. If the required Action Pin does not already exist, you can click on theon the dialog to automatically create an Output pin under the appropriate parent node.
For the 'Result' and 'Body Output' entries, you can check on the exact location of each Action Pin by right-clicking on the entry and selecting the 'Find in Project Browser' option.
The 'Nodes' panel, by default, lists the Actions and Activities contained in the Test partition. Click on the 'Body' radio button to list the elements contained in the Body partition. An element must be completely contained in the Body partition to be listed there - if it overlaps with the Test partition in any way, it is treated as being part of the Test partition.
Add or Remove Clauses
To add another Clause, click on theunderneath the 'Clause(s)' list. This inserts a new Clause in the list, and identifies which is the preceding (Predecessor) Clause and (if appropriate) which is the following (Successor) Clause. The remaining fields in the 'Clause(s)' panel are cleared so that you can add Decider and Body Output Action Pins. New Test and Body partitions are immediately added to the element on the diagram, and you can populate these partitions with Activity elements, which are then identified in the 'Nodes' panel.
To remove a Clause, highlight it in the list and click on the. This immediately removes the Clause's corresponding partitions from the diagram, along with all their contained Activity elements. Removing a Clause from between two other Clauses adjusts the numerical order; for example, if Clause 2 is removed from between Clause 1 and Clause 3, Clause 3 is renamed as Clause 2, and any further Clauses are also moved up one place.
OMG UML Specification:
The OMG UML specification (UML Superstructure Specification, v2.1.1, p.355) states:
A conditional node is a structured activity node that represents an exclusive choice among some number of alternatives.
A conditional node consists of one or more clauses. Each clause consists of a test section and a body section. When the conditional node begins execution, the test sections of the clauses are executed. If one or more test sections yield a true value, one of the corresponding body sections will be executed. If more than one test section yields a true value, only one body section will be executed. The choice is nondeterministic unless the test sequence of clauses is specified. If no test section yields a true value, then no body section is executed; this may be a semantic error if output values are expected from the conditional node.