-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Here are some points to note for each design pattern
Observer pattern:
– Observers/Subscribers must be notified of any changes in Subject/Publishers
– Publishers should push/notify and Subscribers should pull required data.
– Push should be metadata (for example only the changed data index) for Subscribers to ascertain what to do.
– For selective subscription, we should create categories of notifications
– Analogous to Broadcast communication
Example: The code uploaded here is an application which is used to store some data in a text file “data.txt”. This data is handled by a Data Manager class which is responsible for modifying this data as needed by the application. Data Manager is the publisher which has to maintain the set of subscribers and the category of notifications they subscribed to, this responsibility lies in Publisher class which is a base class.
Coming to subscribers, we have various views like text view, bar chart view that display this data and need to be updated whenever there is a change in it.
You can also think of this as Model-View-Controller (MVC) where Model is Data Manager, View is different views and Application is Controller.