UML Analysis Using State Diagrams
UML Analysis Using State Diagrams
net/publication/221610483
CITATIONS READS
3 3,832
3 authors, including:
All content following this page was uploaded by D.A. Gustafson on 25 October 2014.
Abstract — This article demonstrates a new approach to in and the transitions which cause that object to change
analyzing UML designs using state and sequence state. A state diagram provides the component view of an
diagrams. From multiple state diagrams, a super-state object. To understand how the states of one object
diagram which includes the cross-product of the selected interact with the states of another object, a different
states is built along with a transition matrix of possible approach has to be used.
transitions. The closure of the transition matrix is used to
identify unreachable states and impossible transitions. The UML specification does not enforce any consistency
Additionally, the closure is also used to evaluate requirements between the information contained in the
consistency between the state diagrams and the sequence sequence and state diagrams. While this does allow for
greater flexibility in how UML can be used, it can lead to
diagrams. Missing and impossible sequences can be
inconsistent views of the system being modeled. The
identified. A prototype tool has been built to calculate the
problem of relating state diagrams with sequence
closure of the transition matrix and to compare the
diagrams has recently been the focus of research in the
results with the sequence diagrams. software engineering community [e.g. 1]. However, the
work has usually involved just one state diagram and one
1. Introduction or more sequence diagrams.
Finding errors in software designs before they are Our approach to consistency analysis combines the state
implemented is very important. Most researchers in information of multiple state diagrams into a composite
software engineering have found that the earlier an error super-state diagram. This super-state diagram details all
is found, the easier it is to correct. If we can improve the of the possible composite states the objects can be in as
analysis capabilities for software designs, we may have a well as the transition pairs which lead from one
significant impact on removing faults earlier in the composite state to another. In this way the super-state
software development process. diagram provides the complete collaborative view of a set
of objects in the model. A given sequence diagram then
The typical software design is specified using UML should be a valid subsequence of the set of sequences that
diagrams [7] including class diagrams, use case and are possible in a super- state diagram.
sequence diagrams, and state diagrams. Although class
diagrams and use case/sequence diagrams are the most 2. Transition Matrix
common diagrams in a software design, the state diagram
provides an excellent notation for specifying the behavior The basis of our analysis techniques is a transition matrix
of objects and how methods affect the objects. that details the possible global states of the system based
on a vector of states of individual instances of classes and
Sequence diagrams are interclass (interobject or the possible transitions between the states in the global
interagent) and they detail how objects in the model state vector. Consider a program that has class X and
interact via method calls. A sequence diagram can be class Y. Let class X have an initial state A and two other
viewed as a partial collaborative view of a set of objects. states, B and C, while class Y has an initial state D and a
Transitions in a sequence diagram occur as the result of second state E. The state diagrams will depict how
method calls between objects. Methods of different instances of X and Y can transition between those states.
objects are often paired together as the result of one Let class X call class Y whenever class X transitions
object’s method calling the method of another object. between state A and B. Table 1 shows possible
transitions in the super-state diagram that is the cross-
A state diagram is intraclass (intraobject or intraagent) product of all states with one instance of X and one
and it describes the states one object in the model can be instance of Y.
Table 1 - Super-state transition matrix T1.
T1 AD BD CD AE BE CE
AD 0 0 0 0 1 0
BD 1 0 1 0 0 0
CD 0 1 0 0 0 0
AE 0 1 0 0 0 0
BE 0 0 0 1 0 1
CE 0 0 0 0 1 0
3. Error Discovery
The closure of the transition matrix for a cross-product of
a number of instances will be the basis for our analysis.
The closure of the transition matrix by itself can show
four kinds of errors:
1. existence of a bad combination of states
2. unreachability of a good combination of states
3. existence of a bad transition
4. unreachability of an important transition
4. Library Example
This example describes the interaction between a patron
of a library and the copies of books the library holds. In
order to simplify the model the library holds only one
copy of each book. Figure 1 is the class diagram for this
model and Figure 2 and Figure 3 are the state diagrams
for the patron and book objects. Note that the transitions
in the state diagrams are numbered for ease of reference.
This example along with the sequences diagrams was
Figure 3 – State Diagram for Patron
created by a team of students trying to create a correct
model of a simple library system.
The patron object can be in one of three states; Good Table 2 - Portion of A1
Standing, Too Many Books, and Overdue Fines. We will GOO GOC GOD GOR GCO
call these states G, T, and F respectively for the rest of GOO 1,21 1,11
this paper. A patron starts in G until the number of books GOC 26 23 2,22
the patron has checked out is equal to MAX or the patron GOD
returns an overdue book. In the former, the patron will GOR 25
transition to state T where they will remain until they GCO 16
return a book. In the latter, the patron will transition to F
where they will not be able to do anything until they pay The row headings are the initial states and the column
the fine that is owed. Note that this does not allow the headings are the final states. The numbers in the table
patron to return additional books if they currently owe a arise from Figure 2 and Figure 3. For the purpose of
fine (a subtle and unintended difference from most actual clarification we have assigned unique numeric identifiers
library systems). to the transitions for each instance of an object in our
system. The book object has two numeric identifiers for
A book object has four states; On Shelf, Checked Out, each transition since we have two instances of that object.
Overdue, and Returned. We will call these states O, C, D, For example, GOO → GOC represents a patron in good
and R respectively for rest of this paper. When a book is standing checking out the second book. The 1 indicates
checked out it transitions from O to C. the patron took the transition labeled checkout [n < MAX]
and the 21 indicates the second book took the transition
The two transitions from C labeled check represent the labeled checkout. If there is an entry for a cell in the
library determining if the book is overdue. If the book is matrix then the transition is valid.
overdue it will transition to D. Otherwise it will transition
to R where it will remain until the library places it back A2 is defined as A1 · A1 which identifies all the states we
on the shelf. can reach in two steps. Table 3 shows a portion of A2.
For our analysis we will assume the library has only one Table 3 - Portion of A2
patron and two books. We now pair the transitions from GOO GOC GOD
the patron and book objects that can occur together. An GOO (1,21)(26) (1,21)(23)
‘X’ indicates we are not concerned about the state of the GOC (2,22)(25) (26)(26) (26)(23)
object.
GOD
GOX → GCX GOR (25)(1,21)
patron checks out a book GCO (2,12)(15)
GXO → GXC
GCX → GRX
patron returns a book on time From Table 3 we can observe that it is possible to go from
GXC → GXR
GDX → FRX GOC to GOO by first returning the second book and then
patron returns an overdue book shelving it.
GXD → FXR
TCX → GRX patron with MAX books returns a
TXC → GXR book The closure of A (i.e. A*) for this model occurs after 5
multiplications of A1. Since A* will give all of the
TDX → FRX patron with MAX books returns an
possible sequences through the combined state diagrams,
TXD → FXR overdue book
we would expect the cells for the unreachable states to be
GCC → TCC patron attempts to check out MAX +
empty.
1 books
For this model the unreachable states include two sets.
The following transitions can occur independent of the The first set includes the states where the patron is in T
states of the other objects and one of the two books is in O or R. Clearly the patron
can not have MAX books checked out if one of the books
F→G patron pays fine is not checked out. The other set of unreachable states
C→D book becomes overdue occurs when the patron is in F and one book is in C and
C→C book remains checked out the other is in D or both books are in C or D. In order for
R→O book is re-shelved the patron to be in F one of the two books would have
had to have been returned. An analysis of A* for this
The initial transition matrix A1 has column and row model shows that the columns for these unreachable
headings with triples representing the states of the three states are empty.
objects. For this model there are 3 · 4 · 4 = 48
combinations of the three objects. Table 2 shows a Some of the faults in the design of the library example
portion of the initial transition matrix A1. can be discovered by simply analyzing the transition
matrix. One such fault was a missing transition. From If a user has no preference of the state of a particular
FRC and FCR there is not valid single-step transition to object in a composite state, then an x can be used to
FRR. This means that if one book is returned late, the denote “don’t care.” For example, to show the effect of
patron goes to F status and can not return the other book calling putOnShelf on the first book, which has previously
until they pay the fine. been returned, the user input line would read as:
The remainder of the analysis of the library model will be x, Returned, x > putOnShelf > x, On Shelf, x
done using the tool we have developed which implements
our consistency checking approach. Here, the states of the patron and the second book will
remain the same, but the first book will go from R to O.
5. UML Design Analysis Tool
6. Results From the Library Example
The UML Design Analysis Tool is a tool to check
consistency between diagram sets within a single Rational We now present the output we obtained after running the
Rose Project and a Transition Set that is user defined. tool on several sequence diagrams developed for the
These XMI files are created from Rational Rose via XMI library example.
export. The file contains an XMI representation of all
models created within the project set. The Transition Set
is a text based file created by the user and is documented
in a later section. These files are parsed into an
appropriate data structure for validation based
comparisons. A set of results is generated in the form of
error messages and are displayed in text upon program
completion.
In this paper we have shown how consistency checking [6] Boris Litvak, Shmuel Tyszberowics, and
between state and sequence diagrams can be AmiramYehudai. “Behavioral Consistency Validation
accomplished through the use of a transition matrix for a of UML Diagrams”. Proceedings of the First
vector of states representing the state of more than just International Conference on Software Engineering and
one instance object. The closure of this transition matrix Formal Methods, pages 118--125, 2003.
can be used to identify reachable and unreachable states,
identify which transitions are valid, to validate class [7] OMG Unified Modeling Language Specification,
diagrams, and to validate sequence diagrams. Version 1.5, Object Management Group, 2003,
http://www.uml.org
We also introduced the UML Design Analysis Tool
which implements our consistency checking [8] Orest Pilskalns, Anneliese Andrews, Sudipto Ghosh,
methodology. We have shown how our methodology and Robert France. “Rigorous Testing by Merging
accurately identified the sequence diagrams which were Structural and Behavioral UML Representations”. UML
inconsistent with the state diagrams. 2003 - The Unified Modeling Language: Modeling
Languages and Applications, 2863: 234--248, 2003.
Further work needs to be done to show that these
techniques can be used on more complex State Diagrams
such as those that include concurrency and nested states.
We are also working on automating the process of
identifying the transition pairs.