Commit 3f939923 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

new exercises about operation implementation

parent facc5922
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies></dependencies>
<groupId>fr.unantes.construction</groupId>
<artifactId>examples</artifactId>
<version>1.0</version>
</project>
......@@ -44,6 +44,23 @@
sensitive,
texcl
}}{}
\lstnewenvironment{ocl}{\lstset{language=[decorative]OCL,
frame=tb,
tabsize=3,
morekeywords={implies,result,flatten,body,init,OrderedSet,self,Tuple,TupleType,def,attr,oclIsUndefined,oclIsInvalid,OclState,let,in},
morecomment=[l]{--},
basicstyle=\footnotesize,
keywordstyle=\bfseries,
ndkeywordstyle=\bfseries,
commentstyle=\itshape,
stringstyle=\ttfamily,
showspaces=false,
flexiblecolumns,
literate={->}{$\to$}{2} {--}{-$\,$-}{2} {<=}{$\le$}{2} {>=}{$\ge$}{2} {<>}{$<\,>$}{3},
sensitive, extendedchars, texcl}}{}
\newcommand{\code}[1]{\lstinline{#1}}
\graphicspath{{./img/}}
......@@ -108,7 +125,7 @@
%\begin{questions}
\chapter{Mapping UML Designs to Code}
\chapter{Mapping UML Designs to Code \\ Structural Aspects}
During Software Construction, the mapping between design models and source code is essential.
......@@ -303,6 +320,95 @@ Remember that you must handle the handshake problem.
\end{question}
\chapter{Mapping UML Designs to Code \\ Behavioral Aspects}
\section{Implementing Operations from pre- and post-conditions specifications}
Consider the class \code{Interval}, illustrated by Figure~\ref{fig:interval}.
This class has one invariant (Listing~\ref{lst:interval:inv}) and two operations,
\code{overlapsWith()} (Listing~\ref{lst:overlaps}) and \code{includes()} (Listing~\ref{lst:includes}).
\begin{figure}[htbp]
\centering
\includegraphics[width=.4\linewidth]{Interval.png}
\caption{The class «Interval»}
\label{fig:interval}
\end{figure}
\lstset{caption={Interval invariant},label=lst:interval:inv,float=htbp}
\begin{ocl}
context Interval(T)
inv: self.end > self.begin
\end{ocl}
\lstset{caption={Operation overlapsWith()},label=lst:overlaps,float=htbp}
\begin{ocl}
context Interval(T)::overlapsWith(other : Interval(T)):Boolean
-- This interval overlaps with another if it includes the others begin or end values
-- or if the other contains this interval begin value.
post: result = self.includes(other.begin) or self.includes(other.end) or
other.includes(self.begin)
\end{ocl}
\lstset{caption={Operation includes()},label=lst:includes,float=htbp}
\begin{ocl}
context Interval(T)::includes(value : T):Boolean
-- This interval includes a value if it is between begin and end.
post: result = value >= begin and value <= end
\end{ocl}
\begin{question}
First, implement the class «Interval» and its two attributes, without the two operations.
Propose an approach to ensure that the class invariant will never be violated.
\end{question}
\begin{solution}
Sorry no correction for now, but I guess the invariant can be checked in the constructor and both attributes could be final.
\end{solution}
\begin{question}
Second, implement the operations \code{includes()} and \code{overlapsWith()}, respecting the post-conditions specified above.
\end{question}
\begin{solution}
\lstinputlisting[language=Java]{./src/main/java/fr/unantes/agenda/Interval.java}
\end{solution}
\section{Implementing Operations from Activity diagrams}
\code{Event}
\code{RecurringEvent}
Event::conflictsWith(other : Event): Boolean
RecurringEvent::conflicts(other : Event): Boolean
RecurringEvent::conflicts(other : RecurringEvent): Boolean
daily x daily
daily x weekly
daily x monthly
daily x yearly
weekly x weekly
weekly x monthly
weekly x yearly
monthly x monthly
monthly x yearly
yearly x yearly
Repetition: daily, weekly, monthly, yearly
\end{document}
......
package fr.unantes.agenda;
/**
* Created on 13/02/2018.
*
* @author sunye.
*/
public class Interval {
}
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Calendar UML</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.eclipse.sirius.nature.modelingproject</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_zgybUBCeEeiFsNUTFhALig" name="NewModel"/>
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style">
<viewpoint:DAnalysis xmi:id="_zgTTIBCeEeiFsNUTFhALig" selectedViews="_ziu8EBCeEeiFsNUTFhALig _zi1CsBCeEeiFsNUTFhALig _zi234BCeEeiFsNUTFhALig _zi5UIBCeEeiFsNUTFhALig _zi7wYBCeEeiFsNUTFhALig" version="12.1.0.201708031200">
<semanticResources>model.uml</semanticResources>
<ownedViews xmi:type="viewpoint:DView" xmi:id="_ziu8EBCeEeiFsNUTFhALig">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Reused']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" xmi:id="_zi1CsBCeEeiFsNUTFhALig">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Capture']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" xmi:id="_zi234BCeEeiFsNUTFhALig">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Design']"/>
<ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" xmi:id="_12P21xCeEeiFsNUTFhALig" name="Calendar Class Diagram" repPath="#_12IiEBCeEeiFsNUTFhALig">
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Class%20Diagram']"/>
<target xmi:type="uml:Model" href="model.uml#_zgybUBCeEeiFsNUTFhALig"/>
</ownedRepresentationDescriptors>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" xmi:id="_zi5UIBCeEeiFsNUTFhALig">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Review']"/>
</ownedViews>
<ownedViews xmi:type="viewpoint:DView" xmi:id="_zi7wYBCeEeiFsNUTFhALig">
<viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Extend']"/>
</ownedViews>
</viewpoint:DAnalysis>
<diagram:DSemanticDiagram xmi:id="_12P20BCeEeiFsNUTFhALig" name="Calendar Class Diagram" uid="_12IiEBCeEeiFsNUTFhALig">
<ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_12P20RCeEeiFsNUTFhALig" source="DANNOTATION_CUSTOMIZATION_KEY">
<data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_12P20hCeEeiFsNUTFhALig"/>
</ownedAnnotationEntries>
<ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_12S6IBCeEeiFsNUTFhALig" source="GMF_DIAGRAMS">
<data xmi:type="notation:Diagram" xmi:id="_12S6IRCeEeiFsNUTFhALig" type="Sirius" element="_12P20BCeEeiFsNUTFhALig" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_12S6IxCeEeiFsNUTFhALig" type="2001" element="_12P21BCeEeiFsNUTFhALig">
<children xmi:type="notation:Node" xmi:id="_12ThMBCeEeiFsNUTFhALig" type="5002">
<layoutConstraint xmi:type="notation:Location" xmi:id="_12ThMRCeEeiFsNUTFhALig" y="5"/>
</children>
<children xmi:type="notation:Node" xmi:id="_12g8kBCeEeiFsNUTFhALig" type="3005" element="_12P21RCeEeiFsNUTFhALig">
<styles xmi:type="notation:ShapeStyle" xmi:id="_12g8kRCeEeiFsNUTFhALig" fontName=".AppleSystemUIFont"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_12g8khCeEeiFsNUTFhALig"/>
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_12S6JBCeEeiFsNUTFhALig" fontName=".AppleSystemUIFont" fontHeight="8"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_12S6JRCeEeiFsNUTFhALig" width="481" height="105"/>
</children>
<styles xmi:type="notation:DiagramStyle" xmi:id="_12S6IhCeEeiFsNUTFhALig"/>
</data>
</ownedAnnotationEntries>
<ownedDiagramElements xmi:type="diagram:DNode" xmi:id="_12P21BCeEeiFsNUTFhALig" width="-1" height="-1" resizeKind="NSEW">
<target xmi:type="uml:Model" href="model.uml#_zgybUBCeEeiFsNUTFhALig"/>
<semanticElements xmi:type="uml:Model" href="model.uml#_zgybUBCeEeiFsNUTFhALig"/>
<ownedStyle xmi:type="diagram:WorkspaceImage" xmi:id="_12P21RCeEeiFsNUTFhALig" showIcon="false" labelPosition="node" workspacePath="/org.obeonetwork.dsl.uml2.design/icons/empty.svg">
<description xmi:type="style:WorkspaceImageDescription" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Reused']/@ownedRepresentations[name='Reused%20Description']/@defaultLayer/@nodeMappings[name='Empty%20Diagram']/@style"/>
</ownedStyle>
<actualMapping xmi:type="description_1:NodeMapping" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Reused']/@ownedRepresentations[name='Reused%20Description']/@defaultLayer/@nodeMappings[name='Empty%20Diagram']"/>
</ownedDiagramElements>
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Class%20Diagram']"/>
<filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_12P21hCeEeiFsNUTFhALig"/>
<activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.obeonetwork.dsl.uml2.design/description/uml2.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Class%20Diagram']/@defaultLayer"/>
<target xmi:type="uml:Model" href="model.uml#_zgybUBCeEeiFsNUTFhALig"/>
</diagram:DSemanticDiagram>
</xmi:XMI>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment