Representing complex systems with Harel statecharts

David Harel realized that:

“A complex system cannot be beneficially described in this naive fashion, because of the unmanageable, exponentially growing multitude of states, all of which have to be arranged in a ‘flat’ unstratified fashion, resulting in an unstructured, unrealistic, and chaotic state diagram.”

He concluded the following:

“To be useful, a state approach must be modular, hierarchical and well-structured.”

Harel introduced elements for modeling complex systems with finite state diagrams and also introduced the term “statecharts”, defined as:

“statecharts = state-diagrams + depth + orthogonality + broadcast communication”

Using composite states and substate machines, we are able to bring more depth into state diagrams, while keeping the diagrams clear and well-structured. Regions help us to express orthogonality: Different substate machines that can be executed side by side. Events allow us to achieve broadcast communication and give us a strong means to describe complex behavior. Using conditions, we can state that a certain event is fired only if a given condition is met. Inter-level transitions, history states, temporal logic as well as entry, exit and throughout actions are further Harel statechart elements.

Harel vs Mealy

Now let us extend the Mealy statechart with more details about what is happening on the ferry at habor: The ferry can take three cars. The mate has to admit these or let them out after arrival. At sea the lifts to the parking spaces shall be locked, so that the passengers stay on deck. The resulting state machine looks like the following:

Extended Ferry example as basic state machine

Extended Ferry example as basic state machine

For every car that leaves or enters and also for both sides we use a state. This blows up the state machine. With the means of composite states and conditions we are able to minimize the state machine again by describing the same behavior. The following image describes the ferry behavior as a Harel statechart. It illustrates composite states, guard conditions and inter-level transitions.

Ferry example as a Harel statechart

Ferry example as a Harel statechart

The carEnter / carLeave states were substituted by a composite state FerryStops with a substate machine that describes the behavior of the ferry at harbor. The lifts to the car deck shall be locked, because passengers must be there during transfer. There are transitions crossing the hierarchy from the substate machine to the upper-level states (inter-level transitions) like the one from state LockLifts to Northwards .