2 RELATED WORK
We consider approaches to be related to our contri-
bution that aim at bridging the gap between the dif-
ferent abstraction levels of formal models and pro-
gram code. This concerns software development
approaches as well as formal method teaching ap-
proaches.
MDSD approaches have the objective of develop-
ing high-level models and derive software from them
(Hailpern and Tarr, 2006). This could be of interest
for our purpose because it embraces different abstrac-
tion levels. Usually, code generation (Brown et al.,
2006) is used that derives program code automati-
cally from a model. This raises difficulties when the
generated code is to be integrated in non-generated
program code, for example in special environments
like Greenfoot. In addition, high-quality program
code is required for teaching purposes, but the qual-
ity of generated code varies depending on the gener-
ator tool. Model round-trip engineering (Sendall and
Kster, 2004) concepts relate generated program code
to high-level models, but are based on heuristics and
not unambiguous and therefore inappropriate for our
purpose. Executable models (Luz and da Silva, 2004;
Hen-Tov et al., 2008) interpret model descriptions in-
dependent from programming languages. While this
is a clean single-source approach and also suited to
demonstrate software execution based on high-level
models, it is difficult to express all business logic of a
program in high-level models. For teaching purposes,
this is also not helping to demonstrate the intercon-
nections between formal models and programming.
Approaches for teaching formal methods usually
work at higher levels of abstraction and without com-
prising program code, as stated in the introduction.
When program code is considered, the objective is
usually to verify its correctness by means of for-
mal methods, but at a low level of abstraction. Ex-
amples for this are the formal specification of al-
gorithms (McLoughlin and Hely, 1996; Bubel and
Hhnle, 2008) and specification of protocols (Brakman
et al., 2006). Similar, model checking of program
code (Roychoudhury, 2006) is related to the low-level
semantics of the programming language and thus not
appropriate for teaching the interconnections to high-
level models.
In summary, there is a lack of approaches that
work on multiple levels of abstractions at the same
time and illustrate the relations. This is especially
true with respect to tools appropriate for teaching pur-
poses: MDSD approaches and techniques make as-
sumptions about program code structures and are thus
hard to integrate in special frameworks like Greenfoot
that make conflicting assumptions.
3 EMBEDDED STATE MACHINES
In the last years, approaches were developed that con-
sider program code not only with respect to the se-
mantics of the programming language, but also with
respect to higher-level semantics that can be influ-
enced by the developer. This applies to so-called
internal DSLs (Fowler, 2006), i.e. domain-specific
languages that are embedded in general-purpose lan-
guages (host languages) and provide semantics of
DSLs there. Furthermore, attribute-enabled program-
ming (Schwarz, 2004) uses the capability of modern
programming language versions to incorporate type-
safe, compiled meta data to annotate source code frag-
ments.
Embedded models (Balz et al., 2008; Balz et al.,
2009) build on these concepts to relate program code
fragments to abstract models like state machines.
When an appropriate program code pattern is defined,
different abstraction levels are maintained in the same
program code. Access to the fragments is not only
possible at development time, but also at run time by
means of structural reflection (Demers and Malenfant,
1995). This allows to create an execution framework
that accesses and invokes the fragments.
3.1 Model and Program Code Pattern
The model type we will use for teaching purposes are
in this case state machines. The language chosen for
this implementation is Java (Gosling et al., 2005) with
its Annotations enhancement for meta data inclusion
(Sun Microsystems, Inc., 2004). The program code
pattern is illustrated in 1. The class at the top repre-
sents a state with the class name being the name of
the state. The method in the state class represents a
transition. It is decorated with meta data referring to
the target state class and a “contract” class containing
guards and updates. An instance of an interface type
referred to as “actor” that encapsulates the applica-
tion’s business logic is passed to transition methods.
Its methods are interpreted as action labels since they
are called when the transition fires.
Guards and updates are implemented as two meth-
ods in a so-called “contract” class which is shown at
the bottom of figure 1. Both evaluate expressions to
a boolean value. The guard uses the current variable
values of the state machine to determine if a transition
can fire, the update compares the current values with
the values from the point in time before the transi-
tion fired to determine the changes to the state space.
CSEDU 2010 - 2nd International Conference on Computer Supported Education
310