from <Role> to <Role> ( "," <Role> )* "{" <MessageSignature> ":" ... <MessageSignature> ":" ... "}"
The choice construct represents a set of mutually exclusive paths
triggered by different interactions that could occur between two roles. One of the
roles will be the decision maker, initiating the interaction, and the other role
will be the recipient, reacting to the specific message received.
There are two various of the choice construct, which will be presented below.
The syntax for the directed choice construct is:
from <Role> to <Role> ( "," <Role> )* "{" <MessageSignature> ":" ... <MessageSignature> ":" ... "}"
For example,
CreditCheck from Seller to CreditAgency; choicefrom CreditAgency to Seller { CreditRefused: CreditOk: }
Another example is,
Order from Buyer to Broker; from Broker to Buyer { validProduct(): Order from Broker to Supplier; Confirmation from Supplier to Broker; OrderDetails from Broker to Buyer; invalidProduct(UnknownProduct): }
In this example, the first choice path defines a message signature with only a label (or
operation name), and the second choice path uses the operation name/parameters style of message signature.
The syntax for the directed choice construct is:
choice at <Role> "{" .... "}" or "{" .... "}"
For example,
CreditCheck from Seller to CreditAgency; choice CreditAgency to Seller { CreditRefused from CreditAgency to Seller; } or { CreditOk from CreditAgency to Seller; }
Another example is,Order from Buyer to Broker;
choice at Broker { Order from Broker to Supplier; Confirmation from Supplier to Broker; OrderDetails from Broker to Buyer; } or { invalidProduct(UnknownProduct) Broker to Buyer; }
This example demonstrates one of the main distinctions between the directed and located choice constructs. The direct choice defines the source and destination roles, and each path of the choice construct must send a message between those roles.
In the located choice, as shown in the example above, only the source role is defined, which means that each choice path has the flexibility to send messages to different destination roles. So in the example above, it means that the Broker can communicate with the Supplier before it has to respond back to the Buyer - whereas with the directed choice version of the example, a message needed to be sent back to the Buyer before communicating with the Supplier.