Playing with the JDK’s Observer Pattern Classes

I’m currently reading Head First Design Patterns and I’m really loving their style of writing. They mention that most of the time you will roll your own implementations of Observable (the class that pushes out updates) and Observer (the classes that act on these updates. This is what I’ve seen in my time as a developer too but the JDK also offers the Observable class and the Observer Interface that you can use to do the same.

Unfortunately they have not been updated in a long time and have some issues including:

  • Observable being a concrete class
  • Observable using the deprecated Vector class as the holder for Observers
  • Not using generics to make the code cleaner looking

I’m not sure if my experiments with modifying these classes can be called an improvement but they are up on Github and it was an interesting exercise.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s