Java MVC pattern with observer / observable

Hi,

I have a problem in my application in which I am creating. To give a script, I enter. I have these two controllers both inherit the same initialization model from the main controller. All controllers have their own ideas, but I have only one model.

The problem is that. When changes occur with this model. How can I notify another controller (from two controllers) that an update has occurred? Am I going to use Observer / Observable or PropertyChangeEvent? And how, I got a little confused in the implementation as on MVC archictecture.

Your answer is highly appreciated on this.

Thank you, Cyril H.

+3
source share
3 answers

, PropertyChangeSupport . , - AbstractEntity, PropertyChangeSupport addPropertyListener, removePropertyListener < > firePropertyChange. PropertyChangeSupport. , addPropertyListeners, .

:

  • .
  • , , :
  • java.beans.PropertyChangeSupport
  • java.beans.PropertyChangeListener

public void setValue(String value){
      String oldValue=getValue();
      this.value=value;
      firePropertyChange("value",oldValue,getValue()); 
}

+2

. (PropertyChange - ). , ?

, , . ?

+1

I don't see any problems

  • make your model observableand
  • your supervisor / s

Or type a listenerif the first doesn't suit you.

+1
source

Source: https://habr.com/ru/post/1785145/


All Articles