Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

A better way to do ChangeListeners?

mfortnerJan 20 2013 — edited Jan 20 2013
I find myself having to implement multiple change listeners in a single class, and I was wondering if there was a way to do this that wouldn't trigger compilation problems. For example, let's say you have a LineChart, and you want the chart to listen for changes to the data, but also changes to the user's smoothing algorithm selection. You might try declaring your class like this:
public class MyGraph implements DataChangeListener, SmoothingChangeListener {....
where you've declared DataChangeListener, and SmoothingChangeListener as
DataChangeListener extends ChangeListener<SomeDataStructure>{...}

SmoothingChangeListener extends ChangeListener<ISmoothable>{...}
The compiler will tell you immediately that MyGraph can only implement one ChangeListener.

In real life, I have classes that have to listen for multiple types of events, and both for the sake of semantic clarity and for the sake of feasibility, they need to implement those change listeners. I've used event buses in certain cases, but they tend to obscure what the class is actually listening to.

Is there a better way of doing this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2013
Added on Jan 20 2013
5 comments
411 views