Corrected link
parent
53fb6e1d61
commit
d188a1126a
|
@ -2,4 +2,4 @@
|
|||
|
||||
Musterlösung:
|
||||
|
||||
pr2.lambda.observer](../../solutions/src/main/java/pr2/lambda/observer/).
|
||||
[pr2.lambda.observer](../../solutions/src/main/java/pr2/lambda/observer/).
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package pr2.lambda.observer;
|
||||
|
||||
public interface Beobachter {
|
||||
int getValue();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
package pr2.lambda.observer;
|
||||
|
||||
public class Datenhalter {
|
||||
|
||||
private final int geheimerWert;
|
||||
|
||||
public Datenhalter(int geheimerWert) {
|
||||
this.geheimerWert = geheimerWert;
|
||||
}
|
||||
|
||||
public Beobachter getBeobachter() {
|
||||
return new BeobachterImpl();
|
||||
}
|
||||
|
||||
private class BeobachterImpl implements Beobachter {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return geheimerWert;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
package pr2.lambda.observer;
|
||||
|
||||
public class DatenhalterAnonym {
|
||||
|
||||
private final int geheimerWert;
|
||||
|
||||
public DatenhalterAnonym(int geheimerWert) {
|
||||
this.geheimerWert = geheimerWert;
|
||||
}
|
||||
|
||||
public Beobachter getBeobachter() {
|
||||
return new Beobachter() {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return geheimerWert;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
package pr2.lambda.observer.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pr2.lambda.observer.Beobachter;
|
||||
import pr2.lambda.observer.Datenhalter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class BeobachterTest {
|
||||
|
||||
@Test
|
||||
void testBeobachter() {
|
||||
Datenhalter dh = new Datenhalter(42);
|
||||
Beobachter b = dh.getBeobachter();
|
||||
assertEquals(42, b.getValue());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue