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 ...

Get Joy of Patterns: Using Patterns for Enterprise Development, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.