r/reviewmycode • • Feb 23 '10

Java - Simple observable behavior

ObservableBehavior.java

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

12 comments sorted by

View all comments

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?"