0

I'm working in a java project with Socket, MVC Pattern and Observer/Observable Pattern. I have to do a double notify from a Controller to a view like follow:

    this.game.notifyObservers(new InfoMessageType(InfoMessageTypeEnum.SHOWINITIALMMESSAGE, this.game));
    this.game.notifyObservers(new InfoMessageType(InfoMessageTypeEnum.SHOWGAMEBOARD, this.game));

The problem is that the first notifyObservers works well, but the seconds look like it doesn't works. I tried to comment the first notifyObserver and the second now works fine. it seems like is not possible to do a multiple notifyObserver.

For istance: the first notifyObserver contain the String "Game Ready" the second notifyObserver contain the String "GameBoard Status: "

The Output is just: "Game Ready"

And if I comment the first notifyObserver the output is "GameBoard Status: "

I don't have any java runtime error, just don't print what I want.

How can I resolve it?

EDIT: before notifyObservers calls I add the observers like follow

for(ServerSocketView serverSocketView : serverSocketViews)
    this.game.addObserver(serverSocketView);

And i never remove the observers from the game and from the methods that i call

G.Joe
  • 37
  • 5
  • Would you add your `notifyObservers ` method? Is it the case that this method removes the game Observers? – Mad Matts Jun 09 '16 at 08:57
  • before notifyObservers calls I add the observers like follow **for(ServerSocketView serverSocketView : serverSocketViews) this.game.addObserver(serverSocketView);** And i never remove the observers from the game and from the methods that i call @MadMatts – G.Joe Jun 09 '16 at 09:39
  • Would you show us your `notifyObservers` anyway? This would help. – Mad Matts Jun 09 '16 at 09:46

0 Answers0