There two ways to create an instance during runtime in xUML: signaled (asynchronous) and with the create action (synchronous).
Creation with a signal (asynchronous)
With this approach a creation signal is sent and, upon dispatch, the model execution domain takes care of creating the new instance and placing it in an initial state as designated on the target class’s state model. Any parameter values supplied with the creation event are made available to the new instance’s creation activity. Further, the MX domain ensures that a complete and correctly linked instance is in place at the conclusion of the creation activity. All necessary attributes and links to other objects as indicated on the class model must be in place upon conclusion of the creation activity.
This style of creation is called asynchronous since the sending object can continue about its business, advancing through states, etc. without any immediate feedback regarding the creation status.
To perform asynchronous creation, send a signal to a class name (not an instance set variable) and precede the class name with the
* new instance operator.
New folder( Parent: parent id ) -> *Folder
All data necessary to create a complete instance of Folder must be available to the creation state. Though, not all data need be specified as parameters on the creation event if that data is available elsewhere, such as in attribute initialization values specified on the class model.
The Create folder event will be defined as a creation event on the Folder state model. But the
* is helpful to clarify to the model reviewer that a new instance is created. It also encourages the model developer to be explicit about their intention. Consider a non-creation event sent to all instances of Folder:
Close -> Folder(*)
In the above example a Close event will be sent to each instance of Folder. Appearing in the context of selection, the
* symbol means “all”.
So, yes, the meaning of some keyboard characters varies depending on context. We try to keep this sort of thing to a minimum.
Creation with an action (synchronous)
The create action creates an instance immediately and returns an optional link to the newly created instance. It is synchronous because the creation begins and ends within a single action inside of an activity.
To create a new instance, use the new
* operator with initial values supplied:
ac .= *Aircraft( Tail:t, Altitude:a, Heading:h, Location:l, Airspeed:s, state: .Flying )
There are no “not applicable” or “null values” permitted in xUML. So you either create a complete instance or you don’t. This is a necessary consequence of the underlying set theory. It is also a consequence of not assuming anything about the memory implementation.
If an attribute is omitted from the creation action, the attribute’s specified initialization value indicated on the class model will be used.
Note that an optional initial state is specified in the above example. Each state model diagram should designate one or more possible initial states. Only one of these states may be specified in a creation statement. Normally, however, no state is specified and a single designated initial state is assumed.
Consider a class model where there is a one to many unconditional association R1 between Folder and Document. So both empty folders and folder-less documents are not allowed. This means that if there are no instances of Folder and you want to create an instance of Document, you must create them both at the same time. You can do this by embedding creation actions within a link action:
*Document( Name: in.doc name ) &R1 *Folder( in.folder name )
The action above completes with the creation and linking of a new instance of Document and Folder.