Many classes have instances that are created and deleted over time. Actions can synchronously create and delete instances of other classes without state machines, as shown on these states of the Order in Figure 10.4. Figure 10.4. Order Creates and Deletes Instances of SelectionThe instances of Selection are created and deleted synchronously as part of the procedure. Likewise, the associations between the Order and the Selection are created and deleted directly in the procedures. 10.2.1 Asynchronous Creation and DeletionObjects can be created and deleted asynchronously by sending signals. A generate signal action to <class> creator performs this function:
Figure 10.5 shows how an Order creates a Shipment once its payment is approved. Figure 10.5. Order State Procedure Signals to Create ShipmentExecuting the action language to Shipment creator; causes the new Shipment object to be created. The signal requestShipment then causes the transition from the initial pseudostate into the Creating Shipment state, as shown in Figure 10.6. The event parameters are delivered to the procedure and the procedure is executed on the new, object that now exists. Figure 10.6. New Shipment is Created, Enters its Initial State, and Executes its ProcedureSignaling to creator when there is no transition from the initial pseudostate on that event makes no sense: It just cannot be done. To delete an object, send a signal like any other. If a transition is made into a state with a transition to a final pseudostate, the final transition will be made on completion of the state's procedure, and the object will be gone. 10.2.2 Synchronous Creation and DeletionFigure 10.4 showed how procedures can synchronously create and delete instances of classes without state machines. Synchronous creation and deletion can also be used with care! when the target object has a state machine. Synchronous creation is realized using the ordinary create object action:
The effect of this action is to create an instance of Robot in the specified state, and, once created, the state machine instance can accept events. The procedure for the initial state is not executed, because there was no transition into the state for this execution. Similarly, an action can cause the deletion of an object and its associated state machine instance, no matter which state it is in:
As with initial states, the procedure associated with the state-in-which-the object-is-deleted is not executed. Consequently, it is the responsibility of the developer to remove all links to the about-to-be-deleted object and carry out any other necessary cleanup.
|