Design Patterns - observer mode (publish / subscribe model)

  1. Observer pattern simple implementation, need to be present in the subject collection of the observer, there is an update () , the state change when traversing the calling object observer in the collection, call the update () method implementation notice . The viewer needs to do is override the update () to achieve their own logic, then subscribe to topics, change the status of the information received.
  2. The above mentioned observer mode causes each observer are required to implement the same method update (), which in the actual development is difficult to achieve, it can delegate event mode, the stored collection topic is an event object . event contains information of an object , method name to call , information and other parameters used. Observers do not need to inherit the same interface.

Guess you like

Origin www.cnblogs.com/dengsheng/p/11280320.html