Skip to content
Go back

Statechart Diagrams: Visualizing Complex System Behavior

6 min read

UML diagrams are essential tools in software engineering, and statecharts are among the most powerful for modeling system behavior. This post demonstrates my thought process while creating a statechart and explains why this modeling technique is invaluable.

I posted this here because I completely disagree with how statecharts are taught in FIT5136 - Software Engineering at Monash University. The main justification is that the teaching team does not understand the difference between the usage of statecharts versus activity diagrams.

What Are Statecharts?

Statecharts model the behavior of a single object through its various states and transitions. While this might seem simple at first, statecharts reveal complex interactions that are often overlooked. Many resources confuse statecharts with activity diagrams, but they serve different purposes.

Let me walk you through creating a statechart using a familiar example: an Order object in an e-commerce system.

Note: This post contains multiple diagrams that intentionally showcase the iterative thought process during construction. The early versions may be incomplete or incorrect—this demonstrates the beauty of modern iterative development. It’s perfectly acceptable to create multiple iterations of a statechart to gain better understanding.

Starting Simple: Basic States

We begin by asking fundamental questions about the system:

These basic questions give us our initial states:

Basic States

Understanding Transitions

Now we focus on how the object moves between states. We continue asking the client questions:

These questions help us understand the requirements better:

Transitions

Refining the Model

But wait—we’re not done yet. We need to consider edge cases and business rules:

Based on these considerations, we refine our model:

Refined Model

Questioning Assumptions

At this stage, we should question our initial assumptions. Why do we need a Placed state at all? It seems to serve no clear purpose. Why not start directly with Pending when all requirements are satisfied?

Let’s eliminate the unnecessary Placed state:

No Placed State

Adding Business Rules

We continue refining by adding more business requirements:

Business Rules

Considering Reverse Transitions

When we have multiple states, we must consider what events could cause reverse transitions:

Reverse Transitions

Key Insights from the Process

Through this iterative questioning, we’ve discovered critical business rules:

For transitions from [*] to Pending:

For transitions from Pending to Paid:

Adding the Cancelled State

We continue asking questions to identify missing states:

Cancelled State

System Behavior Explained

In plain English, here’s how our system works:

Unanswered Questions

This process reveals more questions than answers:

Notice how this iterative process not only helps us understand the system better but also uncovers requirements we hadn’t considered initially.

The Iterative Nature

We’re far from complete. As we dig deeper into requirements, we might discover:

This is why statecharts are never truly “complete”—requirements evolve, and our models must adapt.

The statechart above is not complete but serves as a solid foundation for further refinement.

Conclusion

Statecharts enable us to understand requirements more deeply. While we could figure out these requirements without statecharts, the modeling process forces us to ask critical questions and understand system behavior better.

From a technical perspective, this understanding helps us:

The key lesson is that statecharts help us ask better questions about requirements, leading to deeper system understanding and more robust implementations.

Statecharts are an essential part of the software engineering process, helping us model complex behaviors in a clear, visual way that reveals hidden requirements and potential issues.


Share this post on:

Previous Post
Using JPlag for Automated Plagiarism Detection in Programming Assignments
Next Post
TSP Algorithm: Solving the Traveling Salesman Problem with Genetic Algorithms