Observable in Java

前端 未结 9 1902
别那么骄傲
别那么骄傲 2020-12-14 19:30

I\'m trying to understand the Observer and the Observable.

Here\'s an example that I\'m trying to figure out:

public class IntegerDataBag extends Obs         


        
9条回答
  •  余生分开走
    2020-12-14 20:16

    1. Yes. addObserver is a method in the Observable abstract class. See Observable in the Java documentation.
    2. It is added to a list in Observable.
    3. A call to notifyObservers will do nothing until setChanged is set.
    4. You might have multiple Observables in the same application.
    5. Observer is a common design pattern. The usual example is when you have a Model and multiple Views. Each View is an Observer on the Model; if the Model changes, the Views get updated.

提交回复
热议问题