Skip to content

Commit 6d04927

Browse files
author
nicolaiparlog
committed
Defined contract for 'ListenerHandle'.
1 parent 317c73a commit 6d04927

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package org.codefx.libfx.listener;
22

3-
// TODO what should the contract be for created handles? Always attached?
4-
// Answer: Up to the returning method to specify!
5-
3+
/**
4+
* A listener handle can be used to {@link #attach() attach} and {@link #detach() detach} a listener to/from some
5+
* observable instance. Using the handler the calling code must not manage references to both the observed instance and
6+
* the listener, which can improve readability.
7+
* <p>
8+
* A handle is created and returned by methods which connect a listener with an observable instance. This usually means
9+
* that the listener is actually added to the observable but it is also possible to simply return a handler and wait for
10+
* the call to {@code attach()} before adding the listener. It is up to such methods to specify this behavior.
11+
* <p>
12+
* Unless otherwise noted it is not safe to share a handle between different threads. The behavior is undefined if
13+
* parallel calls are made to {@code attach()} and/or {@code detach()}.
14+
*/
615
public interface ListenerHandle {
716

17+
/**
18+
* Adds the listener to the observable. Calling this method when the listener is already added is a no-op and will
19+
* not result in the listener being called more than once.
20+
*/
821
void attach();
922

23+
/**
24+
* Removes the listener from the observable. Calling this method when the listener is not added is a no-op.
25+
*/
1026
void detach();
1127

1228
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* TODO
3+
*/
4+
package org.codefx.libfx.listener;

0 commit comments

Comments
 (0)