The 'event generator' idiom

How and when to make a Java class observable

1 2 3 Page 3
Page 3 of 3

The event generator idiom allows one or more listener objects to be notified of state changes or events provided by an event generator. The number and type of listeners may be unknown at compile-time, and can vary throughout the course of execution. The loose coupling of listeners and event generators make the code easier to change or reuse in changing situations.

Next month

In next month's Design Techniques, I'll continue the series of articles that focus on designing classes and objects. Next month's article will describe several basic object idioms.

A request for reader participation

I encourage your comments, criticisms, suggestions, flames -- all kinds of feedback -- about the material presented in this column. If you disagree with something, or have something to add, please let me know.

You can either participate in a discussion forum devoted to this material, enter a comment via the form at the bottom of the article, or e-mail me directly using the link provided in my bio below.

Bill Venners has been writing software professionally for 12 years. Based in Silicon Valley, he provides software consulting and training services under the name Artima Software Company. Over the years he has developed software for the consumer electronics, education, semiconductor, and life insurance industries. He has programmed in many languages on many platforms: assembly language on various microprocessors, C on Unix, C++ on Windows, Java on the Web. He is author of the book: Inside the Java Virtual Machine, published by McGraw-Hill.

Learn more about this topic

  • Bill's next book is Flexible Java
  • The discussion forum on event generators can be found at
  • Links to all previous Design Techniques articles
  • A description of the "I shall return" idiom, which describes a way to return multiple values from a Java method
  • Recommended books on Java design, including information on the Gang of Four's Design Patterns book
  • A transcript of an e-mail debate between Bill Venners, Mark Johnson (JavaWorld's JavaBeans columnist), and Mark Balbe on whether or not all objects should be made into beans
  • Source packet that contains the example code used in this article
  • A nice page that describes UML.
  • Object orientation FAQ
  • 7237 Links on Object Orientation
  • The Object-Oriented Page
  • Collection of information on OO approach
  • Design Patterns Home Page
  • A Comparison of OOA and OOD Methods
  • Object-Oriented Analysis and Design MethodsA Comparative Review
  • Patterns discussion FAQ
  • Patterns in Java AWT
  • Software Technology's Design Patterns Page
  • Previous Design Techniques columns

This story, "The 'event generator' idiom" was originally published by JavaWorld.

Copyright © 1998 IDG Communications, Inc.

1 2 3 Page 3
Page 3 of 3
How to choose a low-code development platform