• Keine Ergebnisse gefunden

Exercise4EncapsulationonObjectLevel Exercise3ConfinedTypes Exercise2ImmutableClassesintheJDK Exercise1Aliasing PracticeSheet8 AdvancedAspectsofObject-OrientedProgramming(SS2012)

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise4EncapsulationonObjectLevel Exercise3ConfinedTypes Exercise2ImmutableClassesintheJDK Exercise1Aliasing PracticeSheet8 AdvancedAspectsofObject-OrientedProgramming(SS2012)"

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 2012) Practice Sheet 8

Date of Issue: 29.05.12

Deadline: 05.06.12 (before the lecture as PDF via E-Mail)

Exercise 1 Aliasing

a) Give two examples for dynamic aliasing, one where aliasing is desired and one where aliasing has undesired effects.

b) Define the relationship between capturing, leaking and aliasing.

c) Give a solution to the signers issue on slide 8 of chapter 4.

Exercise 2 Immutable Classes in the JDK

Select five classes from the JDK which conform to the definition of immutability as given in the lecture and explain the reason for their immutability.

Exercise 3 Confined Types

Examine the code, available with this practice sheet on the web, with respect to confinedness. The classesProofTreeNodeIt undProofContainershould provide the externally visible interfaces and are thus not confined.

a) Examine the classConfinedList. Can we declare this class as confined? Can we modify the implementation to make it confined?

b) Examine the classProofTreeNodeand answer the same questions as above.

c) Examine the classPTNIteratorand answer the same questions as above.

Exercise 4 Encapsulation on Object Level

Consider the classConfinedListfrom the exercise above. The array stored in the fielddatashould be part of the representation of aConfinedList-object, i.e. we annotate it withrep.

class ConfinedList<T> extends AbstractList<T> implements List<T>, RandomAccess, Cloneable, Serializable { ...

private /*rep*/ transient Object[] data;

...

}

a) Is it possible to annotate the remaining parts of the classConfinedList, such that it conforms to the programming discipline presented in the lecture (slide 4.27)? If not, what is the problem with the implementation?

b) Which properties can the programming discipline guarantee? Compare them with the guarantees given by confined types.

Referenzen

ÄHNLICHE DOKUMENTE

writeObject writes the state of the object o, the states of the objects in the object graph reachable by o and the reference structure to a newly created file with the given

Write a code snippet that leads to a ClassCastException at a cast, that has been inserted by the type erasure. Your code should be legal Java except for the given statement. Hint:

This code snippet would break the guarantee of the type system, that the casts that are inserted by the compiler during the type erasure will never fail. Furthermore, one could not

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

JML.5.5.tar.gz), follow the included install instructions and make yourself familiar with their usage. Use the tools for the following exercises to check your specifications and

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

The following shows you a sample session.. a) Modify server and client, such that the server can handle multiple clients at the same time. All messages shall be displayed immediately

In the following, we use the Equinox implementation of an OSGi Framework. The easiest way to work with Equinox, is using eclipse with the plug-in development tools. You find a