Lifecycle Models

Statechart machines are often associated with classes and use cases.

A statechart machine associated with a class usually represents the lifecycle of a typical instance of that class.

Lifecycle of a Process

An operating system keeps a record of every running program. These records are instances of the process class:

Every Process object has a state property that has one of four values. This value can be changed by external events or by internal events. The changes and events are characterized by a statechart diagram:

Lifecycle of a Window

A desktop window is an instance of a Window class:

Using the buttons in buttons in the upper right corner, users can change the size and location of the window according to the following statechart diagram:

window

Lifecycle of a Sequential Circuits

There are two types of digital circuits: combinational circuits (no memory) and sequential (with memory). A simple example of a sequential circuit is a (mod-3) counter. It remembers a count which users can increment or decrement by one modulo three:

While combinational circuits are specified using truth tables, sequential circuits are specified using statechart diagrams:

Lifecycle of a Scanner

A scanner is a little like a spell checker. Given a string s and a pattern p, it determines if the s matches p:

Of course the pattern can contain wildcards, quantifiers, and ranges. For example, the following pattern characterizes all numerals as strings that begin with an optional sign (+ or -), followed by one or more digits (0 – 9), followed by an optional fraction:

numeral ::= (sign)?(digit)+(fraction)?

A fraction consists of a decimal point followed by one or more digits:

fraction ::= .(digit)+

Equipped with this pattern we can characterize the behavior of the scanner using a statechart diagram:

 

Notice that this diagram can be thought of as an activity diagram because the states correspond to internal activities.

Lifecycle of a Job

A job processing system maintains a record of every job currently being processed. The state of a job indicates its current status. Insurance claims, college applications, loan applications, contracts, help desk tickets, and bug reports are all examples of jobs.

For example, an application processing center for a university maintains an object representing every application received through the university's web site:

Here's the typical lifecycle of an application. Notice that the transition to the verification states can happen in any order, but only after all three have been verified can we determine the final fate of the application: