Skip to content

Instantly share code, notes, and snippets.

@chrisport
Last active August 29, 2015 14:06
Show Gist options
  • Save chrisport/748ba6d5370f769e58b6 to your computer and use it in GitHub Desktop.
Save chrisport/748ba6d5370f769e58b6 to your computer and use it in GitHub Desktop.
public interface FieldsObservable {
// @param <E> the type of the Field and FieldObserver to guarantee compatibility
public <E> void addFieldObserver(Field<? extends E> field, FieldObserver<? super E> fieldObserver);
public <E> void removeFieldObserver(Field<? extends E> field, FieldObserver<? super E> fieldObserver);
public <E> void notifyFieldObservers(final Field<E> field, final E data);
}
public interface FieldObserver<E> {
/**
* To be called when data has changed.
* @param field the Field-tag of the data
* @param data the new data
*/
public void updateData(Field<E> field, E data);
}
//AbstractFieldsObservable to be replaced by component, will look similar to PropertyChangeListener
public interface Profile extends AbstractFieldsObservable {
public static final Field<String> FIRST_NAME = new Field("firstName");
private String firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
notifyFieldObservers(FIRST_NAME, firstName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment