Alternative to Observable and Observer in Java 9

8

For testing purposes, I'm porting an application from version 7 to version 9 of Java.

This application has some features that use Observer and Observable .

I noticed that both have become obsolete:

@Deprecated(since="9") public class Observable extends Object    
@Deprecated(since="9") public interface Observer
asked by anonymous 06.10.2017 / 16:04

1 answer

9

Like any function that becomes obsolete, they do not serve the needs well, have been poorly designed and now have better solutions.

These types were too general, did not carry important information about the event, and were not so secure from the point of view of typing.

People complained that they were not able to handle competition and serialize the object.

Official position:

  

They do not provide a rich enough event model for applications. For example, they support the notion that something has changed, but they do not convey any information about what has changed. There are also some thread-safety and sequencing issues that can not be fixed compatibly.

Font .

The whole pattern was misunderstood . That's why you should be careful with design patterns .

One of the alternatives is PropertyChangeListener that is usually more specific, simpler and is what you want.

If you need something more powerful you can use the class Flow . documentation indicates this.

    
06.10.2017 / 16:34