• Keine Ergebnisse gefunden

Exercise3EncapsulationonObjectLevel Exercise2ConfinedTypes Exercise1ImmutableClassesintheJDK PracticeSheet6 AdvancedAspectsofObject-OrientedProgramming(SS2013)

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise3EncapsulationonObjectLevel Exercise2ConfinedTypes Exercise1ImmutableClassesintheJDK PracticeSheet6 AdvancedAspectsofObject-OrientedProgramming(SS2013)"

Copied!
1
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. A. Poetzsch-Heffter Mathias Weber, M.Sc.

University of Kaiserslautern Department of Computer Science Software Technology Group

Advanced Aspects of Object-Oriented Programming (SS 2013) Practice Sheet 6

Date of Issue: 21.05.13

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

Exercise 1 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 2 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.

d) Download and install the tool “kacheck” from the lecture homepage. This tool is able to check the confinedness of Java classes based on the bytecode of these classes.

Compile Java source files mentioned in this exercise using the java compiler. Afterwards run the command

kacheck -violationson the folder the class files are in.

Compare the output of the tool with the results you expected. Try to explain unexpected results.

Hint: The tool outputs violations for all classes of the Java runtime that are indirectly used. These outputs can be ignored.

Exercise 3 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

Despite this, several single-centre, randomized, controlled trials have successfully applied therapeutic strategies based on information obtained from the pulmonary artery catheter,

a) Implement a method IPlugin load(String clazz) that loads the plugin with the given name. Please also check that the loaded class really implements the needed interface.. b)

Does the print method in class PhDAssistant override the print method in class Person ? Hint: look at the Java Language Specification in Section 8.4.8... Exercise

Collection&lt;E&gt; c = ... Write a generic class TransformingIterator and the accompanying interface Transformer , that decorates an existing Iterator with a transformation

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

After the development has been finalised, we conducted a comparative evaluation study in order to measure whether our efforts in tool engineering translate into annotation

Moreover, by (4.9) one of the last two inequalities must be proper.. We briefly say k-set for a set of cardinality k. Its number of vertices |V | is called the order of H. We say that

Probe trials were inserted among training tri- als to determine whether the contingencies of reinforcement that were used in training would control pigeons' choice