<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Teaching Model Views with UML and OCL</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Loli Burgue n˜o</string-name>
          <email>loli@lcc.uma.es</email>
          <email>loli@lcc.uma.es Marbella International University Centre, Spain lola@miuc.org</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Antonio Vallecillo</string-name>
          <email>av@lcc.uma.es</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Martin Gogolla</string-name>
          <email>gogolla@informatik.uni-bremen.de</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Universidad de Ma ́laga</institution>
          ,
          <country country="ES">Spain</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Universidad de Ma ́laga</institution>
          ,
          <country country="ES">Spain</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>University of Bremen</institution>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>-The specification of any non-trivial system is normally composed of a set of models. Each model describes a different view of the system, focuses on a particular set of concerns, and uses its own notation. For example, UML defines a set of diagrams for modelling the structure and behavior of any software system. One of the problems we perceived with our students is that they are able to understand each one of these diagrams, but they have problems understanding how they are related, and how the overall system specifications work when composed of a set of views. This paper presents a simple case study that we have developed and successfully used in class, which permits students developing the principal views of a system, simulate them, and check their relations.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>I. INTRODUCTION</p>
      <p>Non-trivial systems specifications need to be decomposed
in various models (views), each one focusing on a particular
set of concerns and described in a particular notation. For
example, UML defines a set of diagrams for modelling a
system that permit describing its structure (class diagrams),
the behavior of its individual objects (state machines), the
collective behavior of collections of objects (communication
and sequence diagrams), etc. There are two main problems that
we have perceived with our students when teaching the use of
models. First, they normally tend to see models as drawings,
mostly used for communication among humans, and not as
software artefacts that need to be processed by computers.
Hence they tend to be less precise and formal than when
developing programs. And second, when dealing with
multiviewpoint models, students may be able to understand each
one of these diagrams, but they have problems understanding
how they are related, and how the overall system specifications
actually work when composed of a set of views.</p>
      <p>
        This paper presents a simple case study that we have
developed and successfully used in class, which permits students
to develop the principal views of a system, simulate them,
and understand their relationships. We use a combination
of UML and OCL and the possibilities that the OCL/USE
tool [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] provides to simulate and analyse the models, as proper
software artefacts.
      </p>
      <p>
        The example we present here—originally defined in [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]—
is based on a production line and it is modeled using a
combination of UML and OCL. We show how these notations
permit modeling the system in a formal manner using different
views, and allow performing several interesting analyses on the
system.
      </p>
      <p>
        The rest of the paper is structured as follows. The next
Sect. II describes the example and shows interesting properties
using the USE modeling environment [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. Section III
presents the lessons we learned. Finally, Section IV presents
our conclusions and future work.
      </p>
      <p>II. A UML AND OCL MODEL FOR A PRODUCTION LINE</p>
      <p>SYSTEM</p>
      <p>Let us illustrate our approach by modeling a plant that
produces hammers. This plant is composed of four machines:
one that generates hammer heads, another that generates
handles, one that assembles heads and handles, and finally
one that polishes the hammers. There are also trays that are
used to collect the goods in production.</p>
      <p>The plant operates as follows: each generating machine has
an associated tray, in which it places the heads or handles
as soon as they are produced. From these trays, the pieces
are taken by an assembler machine, which puts together one
head and one handle to produce a hammer, which is placed
in a different tray. From this tray, the polisher takes hammers,
works on them and leaves them in a different tray.</p>
    </sec>
    <sec id="sec-2">
      <title>A. Structural Elements</title>
      <p>Pre- and post-conditions. The behavior of the system can be
expressed in UML and OCL by different means. One of the
most common ways is by adding the specification of pre- and
post-conditions to the operations, defining their behavior. This
is shown below for get() and put() operations of class
Tray.</p>
      <p>put ( p : Part )
pre notFull : self . parts &gt;size ( )&lt;cap
p o s t ElementAdded : self . parts=self . parts@pre &gt;append ( p )
get ( ) : Part
pre notEmpty : self . parts &gt;size ( )&gt;0
p o s t FirstElementRemoved :</p>
      <p>Class diagram
HeadGenerator
counter : Integer
start()
generate() : Head</p>
      <p>PartGenerator</p>
      <p>Assembler</p>
      <p>Polisher
start()
HandleGenerator
counter : Integer
start()
generate() : Handle</p>
      <p>start()
assemble(hd : Head, hl : Handle) : Hammer polish(hm : Hammer)</p>
      <p>Machine</p>
      <p>PlantElement
processingTime : Integer * output MachineConsumption
start()
1..* input</p>
      <p>MachineProduction</p>
      <p>
        Behavior of operations. USE also permits to
specify the behavior of operations using a simple
executable language called SOIL [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. For instance,
the behavior of Assembler::start() and
Assembler::assemble() operations can be specified as
follows.
start ( )
begin
declare hd : Part , hl : Part , hm : Hammer ;
hd:=self . input &gt;select ( t j t . parts &gt;size&gt;0 and
t . parts &gt;forAll ( oclIsTypeOf ( Head ) ) ) &gt;
      </p>
      <p>single ( ) . get ( ) ;
hl:=self . input &gt;select ( t j t . parts &gt;size&gt;0 and
t . parts &gt;forAll ( oclIsTypeOf ( Handle ) ) ) &gt;</p>
      <p>single ( ) . get ( ) ;
hm:=self . assemble ( hd . oclAsType ( Head ) ,</p>
      <p>hl . oclAsType ( Handle ) ) ;
self . output . put ( hm ) ;
end
end
psm PutGet
states
init : initial
Empty [ self . parts &gt;size ( ) =0]
Normal [0&lt;self . parts &gt;size ( ) and</p>
      <p>self . parts &gt;size ( )&lt;self . cap ]</p>
      <p>Full [ self . parts &gt;size ( ) =self . cap ]
transitions
init &gt; Empty f create g
Empty &gt; Normal f [ self . cap&gt;1] put ( ) g
Normal &gt; Normal f [ self . parts &gt;size ( )&lt;cap 1] put ( ) g
Normal &gt; Full f [ self . cap&gt;1 and</p>
      <p>self . parts &gt;size ( ) =cap 1] put ( ) g
Empty &gt; Full f [ self . cap=1] put ( ) g
Full &gt; Empty f [ self . cap=1] get ( ) g
Full &gt; Normal f [ self . cap&gt;1] get ( ) g
Normal &gt; Normal f [ self . cap&gt;1 and</p>
      <p>self . parts &gt;size ( ) &gt;1] get ( ) g</p>
      <p>Normal &gt; Empty f [ self . parts &gt;size ( ) =1] get ( ) g
State machines. UML permits specifying the behavior of indi- assemble ( hd : Head , hl : Handle ) : Hammer
vidual objects by means of State machines that determine how begin
destroy hd , hl ;
their internal state changes as a result of the invocation of their result:=new Hammer ; result . isPolished:=false ;
provided operations. USE/OCL permits formally specifying end
state machines for individual objects, and then automatically Executing the specifications. Once we have the behavior of
deriving the corresponding UML diagram. For example, the the operations, we can execute the system by providing a
following listing shows the specification of the state machine sequence of SOIL commands that create the initial objects
of a Tray. The corresponding UML diagram is shown in of the system, their links, and invokes the operations. Based
Figure 2. on the specifications above, for example, we can show the
students how to simulate the system, by creating an initial
model of the system and invoking the start() operation to
the four machines.
-- Machines
! new HandleGenerator ( ’hag’ )
! new HeadGenerator ( ’heg’ )
! new Assembler ( ’asm’ )
! new Polisher ( ’pol’ )
-- Trays
! new Tray ( ’Handle2Assem’ )
! Handle2Assem . cap : = 4 ;
! new Tray ( ’Head2Assem’ )
! Head2Assem . cap : = 4 ;
! new Tray ( ’Assem2Polish’ )
! Assem2Polish . cap : = 4 ;
! new Tray ( ’Polish2Out’ )
! Polish2Out . cap : = 4 ;
-- Production Line Connections</p>
      <p>Figure 3 pictorially shows a filmstrip of the behavior of
the system as a sequence of snapshots after every
operation execution. Aggregation associations are used to visualize
‘ownership’ between objects (e.g. a part is placed on a tray).</p>
      <p>We have also developed a video with the complete filmstrip1.</p>
      <p>Object interactions. So far we have focused on the structural
view of the system and the behaviour of individual objects.</p>
      <p>UML also permits representing the interactions between
objects by means of Sequence and Communication diagrams.</p>
      <p>With USE/OCL, we are able to automatically derive them from
1http://atenea.lcc.uma.es/Descargas/EduSymp17/3Hammers.mp4?dl=0
the simulation of the system’s behavior described above, in
terms of sequences of operations invocations. First, the
interactions are recreated using the UML sequence diagram shown
in Fig. 4, that is automatically constructed by USE/OCL.</p>
      <p>The behavior can also be displayed as a communication
diagram as in Fig. 5. Interestingly, for every step we can
represent the current states of all the state machines of the Tray
objects—not shown here for space reasons, although they are
similar to the one depicted in Fig. 2 but with the current state
highlighted; the interested reader can see the presentation2 we
have developed to show the state changes. Also, all the code
developed for this case study is available3.</p>
    </sec>
    <sec id="sec-3">
      <title>C. Further analysis</title>
      <p>Once we have the specifications, there are different kinds of
analyses that we can perform on the system that show some
of the potential advantages of developing model-driven system
descriptions with UML and OCL. In particular: visualization
2http://atenea.lcc.uma.es/Descargas/EduSymp17/snapshots-buffer.pdf?dl=0
3http://atenea.lcc.uma.es/Descargas/EduSymp17/sources.zip?dl=0
of complex structures and processes; execution and simulation
of scenarios (operation call sequences); checking structural
properties of the system within states by OCL queries (e.g.
calculating the number of finally produced parts); checking
behavioral properties (e.g., testing the executability of an
operation by testing its pre-conditions); checking for weakening or
strengthening model properties (invariants, contracts, guards)
by executing a scenario with modified constraints; proving
general properties within the finite search space with the USE
model validator, such as structural consistency (i.e. all classes
are instantiable); behavioral consistency (i.e. all operations
can be executed); deadlocks (e.g. construction of deadlock
scenarios due to inadequate buffer capacities), etc.</p>
      <p>The relationships between the views can also be explored
with this approach. One of the most interesting examples
happens when one of the views is changed, and the effects
of this change on the rest of the views. For example, when an
invariant is added or a class is changed or removed; when an
element changes its name; or when a guard for a state change is
altered. Every kind of change in a model has a different impact
on the validity of another model, and therefore it requires the
other model view to be updated. Students can learn from the
effects of each change, and understand how views are related.</p>
      <p>
        Finally, we want to highlight the importance of running
structural tests on the metamodels. One of them concerns
their instantiability and their ability to faithfully represent
the application domain. For example, we decided to ask the
USE model validator [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] to generate a plant configuration
using the system metamodel. The resulting object diagram is
shown in Fig. 6. Interestingly, the produced system is wrong.
The polisher is not connected to any tray that provides it
with hammers. This motivates the need to develop additional,
currently missing invariants (on the structural system level)
and demonstrates the potential usefulness of this approach
for validating these kinds of properties which are normally
overlooked for being considered obvious.
      </p>
      <p>III. LESSONS LEARNED</p>
      <p>Our experience of teaching UML views with USE/OCL has
been very positive. At the beginning the students feel uneasy
with OCL because they are used to build UML models that
are always right (As Bertran Meyer used to say: “Bubbles
never crash”). But they progressively discover the advantages
of being able to check that the models they are building are
correct. Furthermore, they discover the relations between the
different views of a system, and how changes in the model
manifest in the views.</p>
      <p>Another interesting benefit of our approach is that we
can follow an incremental development process for
building the models. Starting from a simple class diagram we
can incrementally add classes, associations, attributes,
operations, invariants, contracts, soil operation implementations
and protocol state machines. Another feature that students
like very much is creating object models. They then discover
that models are more than pictures, but assertions on the
objects that conform a system (and their relationships). This
incremental development process supports direct feedback and
model improvements. They discover that modelling is similar
to programming, in the sense that you write a program and
execute it to check whether its behavior is as you expected.
Students can check their models using various functionalities
available in USE: the diagrams, the evaluation browser, the
class extent, the single object window, the class invariants
window, etc. And they also learn that views are not completely
independent. On the contrary, they are all projections of an
underlying model.</p>
      <p>IV. CONCLUSIONS</p>
      <p>In this paper we have presented a case study modeled with
UML and OCL/USE that has been successfully used to teach
modeling in class. It does not only focus on the different views
of the system but also on the relationships the different models
have among them. Furthermore, we disclose several of the
advantages of modeling with UML/OCL and USE.</p>
      <p>ACKNOWLEDGMENT</p>
      <p>This work is partially funded by the Spanish Research
Project TIN2014-52034-R. We would like to thank the
anonymous reviewers for their valuable comments and suggestions.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>M.</given-names>
            <surname>Gogolla</surname>
          </string-name>
          ,
          <string-name>
            <surname>F.</surname>
          </string-name>
          <article-title>Bu¨ttner, and</article-title>
          <string-name>
            <given-names>M.</given-names>
            <surname>Richters</surname>
          </string-name>
          , “
          <article-title>USE: A UML-based specification environment for validating UML</article-title>
          and OCL,” Sci. Comp. Prog., vol.
          <volume>69</volume>
          , pp.
          <fpage>27</fpage>
          -
          <lpage>34</lpage>
          ,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>J. E.</given-names>
            <surname>Rivera</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Guerra</surname>
          </string-name>
          , J. de Lara,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Vallecillo</surname>
          </string-name>
          , “
          <article-title>Analyzing rulebased behavioral semantics of visual modeling languages with maude,” in Proc. of SLE'08, ser</article-title>
          .
          <source>LNCS</source>
          , vol.
          <volume>5452</volume>
          . Springer,
          <year>2008</year>
          , pp.
          <fpage>54</fpage>
          -
          <lpage>73</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>M.</given-names>
            <surname>Gogolla</surname>
          </string-name>
          and
          <string-name>
            <given-names>F.</given-names>
            <surname>Hilken</surname>
          </string-name>
          , “
          <article-title>Model Validation and Verification Options in a Contemporary UML and OCL Analysis Tool,”</article-title>
          <source>in Proc. Modellierung</source>
          (MODELLIERUNG'
          <year>2016</year>
          ),
          <string-name>
            <given-names>A.</given-names>
            <surname>Oberweis</surname>
          </string-name>
          and
          <string-name>
            <given-names>R.</given-names>
            <surname>Reussner</surname>
          </string-name>
          , Eds. GI, LNI
          <volume>254</volume>
          ,
          <year>2016</year>
          , pp.
          <fpage>203</fpage>
          -
          <lpage>218</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>F.</given-names>
            <surname>Bu</surname>
          </string-name>
          <article-title>¨ttner and</article-title>
          <string-name>
            <surname>M. Gogolla</surname>
          </string-name>
          , “
          <source>On OCL-Based Imperative Languages,” Science of Computer Programming</source>
          , vol.
          <volume>92</volume>
          , pp.
          <fpage>162</fpage>
          -
          <lpage>178</lpage>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>