Java – why does the attribute change listener instead of observable
I had problems with class design until I found observability (using the observer design pattern) and created a small application to solve my problem I am very happy and proud. I use a good principle to solve a problem
Now I'm about to start my main application and just read it
Making a JFrame and Observable Object
Why does the poster suggest not to use observable, but to tell the use of property changes? Are there any problems using observable?
to greet
Solution
The observer and listener patterns are very similar But observers have one weakness: all observations are the same You must implement the logic based on instanceof and cast objects as observable The specific type of the update () method
The audience is different There are many types of listeners For example, mouse listener, keyboard listener, etc Each has several callback methods (keypressed(), keyreleased(), etc.) Therefore, you never have to execute logic. You should answer the question "it's my event" to the event handler
I think that's why the audience model is better