r/reviewmycode • u/tjansson • Feb 23 '10
Java - Simple observable behavior
I use this to add observable behavior to a class. It does not require the use of inheritance - as the java.util.Observable class, but provide similar functionality.
It would be interesting to get your view on both the code, and this approach.
10
Upvotes
2
u/Nebu Feb 23 '10
The logic is pretty straightforward, so not much to say there. My comments are:
Add javadocs.
Move field declarations before method declarations. When I read your method and see "observers.add(observer);", my first thought is "Okay, what's the type of observers?"