• Keine Ergebnisse gefunden

Exercise2BehavioralSubtypingII Exercise1BehavioralSubtypingI PracticeSheet9(HintsandComments) AdvancedAspectsofObject-OrientedProgramming(SS2010)

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise2BehavioralSubtypingII Exercise1BehavioralSubtypingI PracticeSheet9(HintsandComments) AdvancedAspectsofObject-OrientedProgramming(SS2010)"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Dipl.-Inform. Kathrin Geilmann

University of Kaiserslautern Department of Computer Science Software Technology Group

Advanced Aspects of Object-Oriented Programming (SS 2010) Practice Sheet 9 (Hints and Comments)

Exercise 1 Behavioral Subtyping I

a) JML specifications are inherited by subclasses and classes implementing interfaces. A class inherits the visible invariants of its superclasses (-interfaces). See JML Reference Manual 8.2.4

b) The also keyword indicates that the current specification is refining the specification inherited either from the superclass or from the previous declaration of the method in a refinement sequence. Therefore, it is an error if the specification of a non-refining method begins with also (unless it overrides an inherited method).JML Reference Manual 16.4

c) Use the rules to construct the pre- and postconditions for subclasses.

p u b l i c c l a s s C h i l d e x t e n d s P a r e n t { / /@ r e q u i r e s i >= 0 | | i <= 0

/ /@ e n s u r e s (\o l d ( i>=0) => \r e s u l t >= i )

&& (\o l d ( i<=0) => \r e s u l t <= i ) ; i n t m(i n t i ) { . . . }

}

A call to Child.m withi = 0, means that both parts of the precondition are fulfilled and therefor both parts of the postcondition have to be fulfilled too. As i is not assignable, pre- and post-values of i are the same and we get as only possible result 0.

d) • Class A+Class B: ok

• Class C+Class D: No behavioural subtyping. The complete precondition of D.set() isa > 0 || a > 10, and the complete postcondition of D.get() is(true => result > 10) && (true => result > 0).

D d = new D ( ) ;

d . s e t ( 5 ) ; / / ok

. . . d . g e t ( ) ; / / n o t ok , b e c a u s e o f t h e c o n j u n c t i o n .

The invariant changes nothing.

• Class E+Class F: No behavioural subtyping, due to a possible overflow in F.increment(). The overflow breaks the part of the postcondition, that is inherited from E.increment().

Exercise 2 Behavioral Subtyping II

Works analogously to the Reader example of the lecture.

Referenzen

ÄHNLICHE DOKUMENTE

The Master of Science (MSc) degree programmes in Strategic Studies, International Relations, Asian Studies, and International Political Economy are distinguished by

the normal operation, since after wrong timeout expiration, the system moves definitely into the state 7 (p2.p3,p4,p6), which characterizes duplex transmission; however,

Using a new specification, we re- analyze the data on worldwide environmental quality investigated by Gene Grossman and Alan Krueger in their well-known paper on the

false. This does not guarantee that there exists only a single instance of the field for all threads of the program. In the Java memory model, every thread has its own instance of

Since the example program neither uses synchronized blocks nor volatile fields, the value the main threads sets is never synchronized with the background thread. The example can

b) The also keyword indicates that the current specification is refining the specification inherited either from the superclass or from the previous declaration of the method in

Advanced Aspects of Object-Oriented Programming (SS 2010) Practice Sheet 9 Date of Issue: 10.06.10. Deadline: 17.06.10 (until

In the Confined Types approach, encapsulation is seen from a static point of view, where as the alias modes (and ownership types in general) have a notion of encapsulation based