Question: / / fill out the code / / observer . java package question 1 ; public interface Observer { void valueHasChanged ( T newValue )
fill out the code
observerjava
package question;
public interface Observer
void valueHasChangedT newValue;
statevariablejava
package question;
Create an observer that can alert an observer of a value changed
public class StateVariable
public StateVariableObserver observer
public void setValueT newValue
questionjava
package question;
import org.junit.Assert;
import org.testng.annotations.Test;
class Watcher implements Observer
int count;
T lastValueSeen;
@Override
public void valueHasChangedT newValue
count;
lastValueSeen newValue;
public class Question
Create an observer that alerts when a value has changed
@Test
public void test
var watcher new Watcher;
StateVariable intState new StateVariablewatcher;
intState.setValue;
Assert.assertEqualswatchercount, ;
Assert.assertEqualsintwatcherlastValueSeen, ;
intState.setValue;
Assert.assertEqualswatchercount, ;
Assert.assertEqualsintwatcherlastValueSeen, ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
