Observer pattern
definition: defines a one-to-many dependency between objects so that when each object changes state, all objects that depend on it are notified and updated automatically.
Class Diagram:
Several [observers] observe the [observed] state, and when the [observed] state changes, the [observer's] own state changes as well.
The Observer has three methods: The Attach method is to add the Observer object to the container, the detach method is to remove the observer object from the container, and the Notify method is to call the corresponding method of the Observer object in turn.
The observer pattern is a common trigger mechanism that forms a trigger chain and then processes each observer's method in turn.
One advantage here is that the observer does not need to know what the observer is and how many observers it has, but notifies the observer to subscribe to its own state when it is changed.
Add: The difference between a vector and a list
The vector is equivalent to the sequential table in the data structure, the physical address is continuous, the query speed is fast, can be directly subscript index, but when the insertion of data is deleted, the back of all the data to move, less efficient
List is a doubly linked list, the physical address is not contiguous, must be queried from the beginning or the tail, slow, but can dynamically insert delete data
The observer pattern of the design pattern