O'Reilly logo

Joy of Patterns: Using Patterns for Enterprise Development, The by Brandon Goldfedder

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Observer

That wasn't too painful, but now let's consider the same approach in Java. In Java, there is direct language support for the observer. In order to provide a similar solution in Java, we simply implement the observer interface in the class that is to be notified. The observable class can be used to provide the framework for handling the registration and notification of observers. Notice how much more straight-forward this is when the framework is in place. To avoid turning this example into a Java primer, I've avoided doing the GUI in Java (which, unfortunately, is something much more straightforward in Visual Basic than in Java).

Account

 package JavaObserver; import java.util.*; public class Account extends Observable { public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required