摘要:The aim of this study is to find an easy way for implementing concurrent-hierarchical state machines into efficient and encapsulated Java code. State Machine is one of the important diagrams in Unified Modeling Language (UML). In UML, State Machine is used to represent reactive behavior of a class of objects. Implementing a state machine has been difficult for programmers because the commonly used Object-Oriented Programming languages do not provide any explicit support. We present a new approach to implement state machines using Java Enums. In our approach, each state is represented as an enum-value. Hierarchical states and concurrent orthogonal regions within state machines are implemented by linking the related enum-values to each other. Our approach offers several benefits. First, using Java enums makes the resulting code compact, efficient and easy to understand. Second, the structure of the state machine is obvious in the implementation code. Third, the whole state machine's behavior is encapsulated within a single class (called StateMachine). The proposed code can serve as a Java implementation pattern for state machines.