Dankwoord - martes
Dankwoord - martes
Dankwoord - martes
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
2.2. TOOLS 15<br />
Indien het sleutelwoord @pre in een van de postcondities aanwezig is dan is de structuur van<br />
de klasse waarbij deze postconditie behoort uitgebreid. Deze uitbreiding is gevat in een nieuwe<br />
abstracte statische klasse PrePost. Deze nieuwe klasse is een hulpklasse om de toestand van<br />
een variabele of object op te slaan voor de uitvoering van de operatie. Op deze manier worden<br />
pre- en postcondities correct geëvalueerd.<br />
We kunnen nu alles recapituleren in tabel 2.4.<br />
Listing 4 Together 2<br />
class X{<br />
private int attribute;<br />
public void operation(){<br />
OCL.PrePost oclPreState = OCL.preOperation();<br />
// ... <br />
assert(OCL.PrePost.checkPost(oclPreState,null) && OCL.AllInvariants() );<br />
}<br />
protected static class OCL{<br />
private static final boolean isEnabled = X.class.desiredAssertStatus();<br />
private OCL(){<br />
}<br />
protected static abstract class PrePost{<br />
private static boolean checkPost(PrePost preState, Object result){<br />
return preState != null ? preState.post(result) : !isEnabled;<br />
}<br />
protected abstract boolean post(Object result);<br />
}<br />
static protected PrePost preOperation(){<br />
if(!OCL.isEnabled) return null;<br />
PrePost preState = new PrePost(){<br />
// save the preState of the postcondition<br />
protected boolean post(Object _result){<br />
// ... <br />
}<br />
};<br />
return preState;<br />
}<br />
static boolean inv0(){<br />
}<br />
static boolean inv1(){<br />
}<br />
static boolean allInvariants(){<br />
return inv0()&& inv1();<br />
}<br />
static boolean preOperation(){<br />
}<br />
}<br />
}