Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Handle various observers in different ways  RSS feed

 
Jeyaganeshan Jeyatharsini
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example I have an Observable and 2 various obeserver. I need to pass two different type of object to them. How can I use Observer-Observable design pattern in this context? Or Do I need to go for some other ways? If so what's it?
 
Stephan van Hulst
Saloon Keeper
Posts: 7713
141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion it's best not to use Observable and Observer at all, because Observable should have been an interface, and they are not strongly typed.

Instead, write a listener interface for each event that you want to listen for. The class that you want to observe should provide methods that can add and remove listeners for a specific event.

Maybe you can explain a bit more what the different types of objects are that you want to pass around?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!