• Keine Ergebnisse gefunden

Exercise2Abstraction Exercise1IntroductiontoJML PracticeSheet8 AdvancedAspectsofObject-OrientedProgramming(SS2009)

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise2Abstraction Exercise1IntroductiontoJML PracticeSheet8 AdvancedAspectsofObject-OrientedProgramming(SS2009)"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter M.Sc. Yannick Welsch

University of Kaiserslautern Department of Computer Science Software Technology Group

Advanced Aspects of Object-Oriented Programming (SS 2009) Practice Sheet 8

Date of Issue: 16.06.09

Deadline: 22.06.09 (until 10 a.m. as PDF via E-Mail)

Exercise 1 Introduction to JML

TheJava Modeling Languageallows to specify properties of Java software by using special annotations. The JML homepage (http://www.jmlspecs.org) provides tutorials, papers, and tools you can use to solve the following exercises.

a) Summarise advantages of using a formal specification technique such as JML in comparison to informal ap- proaches. Could you think of any „drawbacks“ caused by the usage of formal specification techniques?

b) Make yourself familiar with the conceptual framework provided by JML. Use the paper „Design by Contract with JML“ by Leavens and Cheon as a starting point.

c) Specify the following class. Give pre- and postconditions for the constructor and methods and a non-trivial class and loop invariant.

c l a s s B e h a e l t e r { i n t[ ] a ; i n t n ;

B e h a e l t e r ( i n t[ ] i n p u t ) { n = i n p u t . l e n g t h ; a = new i n t[ n ] ;

S y s t e m . a r r a y c o p y ( i n p u t , 0 , a , 0 , n ) ; }

i n t e x t r a c t M i n ( ) {

i n t m = I n t e g e r . MAX_VALUE;

i n t mindex = 0 ;

f o r (i n t i = 0 ; i < n ; i++) { i f ( a [ i ] <m) {

mindex = i ; m= a [ i ] ; }

} n− −;

a [ mindex ] = a [ n ] ; r e t u r n m;

} }

d) It is obvious that the valuencan only decrease over time. How can you specify this using JML?

e) Specify the JDK classjava.io.ByteArrayInputStreamusingJML.

Exercise 2 Abstraction

a) Explain the necessity for JML’s concept ofmodel fields. Why are these especially important in the context of interface specifications?

b) Specify the followingQueueinterface according to the „well-known behaviour“ of this datastructure.

p u b l i c i n t e r f a c e Queue {

O b j e c t p e e k ( ) t h r o w s E m p t y Q u e u e E x c e p t i o n ; O b j e c t d e q u e u e ( ) t h r o w s E m p t y Q u e u e E x c e p t i o n ; v o i d e n q u e u e ( O b j e c t i t e m ) ;

b o o l e a n i s E m p t y ( ) ; i n t s i z e ( ) ; }

c l a s s E m p t y Q u e u e E x c e p t i o n e x t e n d s E x c e p t i o n {}

Referenzen

ÄHNLICHE DOKUMENTE

– Enforces “Think before you code”. The developer has to think about the precise meaning of the inter- faces he uses, this allows to detect errors and problem quite early in

Starting a method-specification with the keyword also is intended to tell the reader that this specification is in addition to some specifications of the method that are given in

c) Take the interface with the specification and modify it, such that a) it declares a class Queue instead of an inter- face, b) implements all methods, c) relates the

// @ public model instance JMLObjectSequence elements ; // @ initially elements != null &amp;&amp; elements.. c) The method implementation are straightforward, mainly delegate the

a) Model fields form a model state, which can be different from the implemented state.. The model state may be better suited for specifying the behavior of an object, because it can

Undesired dynamic alias: Store an alias to an object in the local variable tmp; hideAll components and make the aliased one visible again. Capturing occurs if a reference, which

a) Explain the necessity for JML’s concept of model fields. Why are these especially important in the context of interface specifications?. b) Specify the following Queue

Advanced Aspects of Object-Oriented Programming (SS 2011) Practice Sheet 8 (Hints and Comments).. Exercise