mercredi 3 février 2016

Update only specific list of observers in Observer Design Pattern based on subscription criteria

I have four Observers who have subscribed to a Subject class. Whenever this Subject receives a message string (eg."type:new,price:2000,count:30"), it sends an update to all the Observers. Each Observer in their update function check for the field they are interested in, and if it exists in the message then they extract the updated value. But I don't want to unnecessarily send the update to all the observers. I only want to send it to those who are interested in particular fields contained in the msg. Eg. Observer1 should be updated only when price>1000.

How can I achieve this using the observer design pattern?

Aucun commentaire:

Enregistrer un commentaire