29.4. Use Case Statechart Diagrams

A useful application of statechart diagrams is to describe the legal sequence of external system events that are recognized and handled by a system in the context of a use case. For example:

  • During the Process Sale use case in the NextGen POS application, it is not legal to perform the makeCreditPayment operation until the endSale event has happened.

  • During the Process Document use case in a word processor, it is not legal to perform the File-Save operation until the File-New or File-Open event has happened.

A statechart diagram that depicts the overall system events and their sequence within a use case is a kind of use case statechart diagram. The use case statechart diagram in Figure 29.2 shows a simplified version of the system events for the Process Sale use case in the POS application. It illustrates that it is not legal to generate a makePayment event if an endSale event has not previously caused the system to transition to the WaitingForPayment state.

Figure 29.2. Use case statechart diagram for Process Sale.


Utility of Use Case Statechart Diagrams

The number of system events and their legal order for the Process Sale use case are (so far) relatively trivial, thus the use of a statechart diagram to show legal sequence may not seem compelling. But for a complex use case with myriad system events—such as when using a word processor—a statechart diagram that illustrates the legal order of external events is helpful.

Here's how: During design and implementation work, it is necessary to create and implement a design that ensures no out-of-sequence events occur, otherwise an error condition is possible. For example, the system should not be allowed to receive a payment unless a sale is complete; code must be written to guarantee that.

Given a set of use case statechart diagrams, a designer can methodically develop a design that ensures correct system event order. Possible design solutions include:

  • hard-coded conditional tests for out-of-order events

  • use of the State pattern (discussed in a subsequent chapter)

  • disabling widgets in active windows to disallow illegal events (a desirable approach)

  • a state machine interpreter that runs a state table representing a use case statechart diagram

In a domain with many system events, the conciseness and thoroughness of use case statechart diagrams help a designer ensure that nothing is missed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.89.123