I. DefinitionThe observer pattern defines a one-to-many dependency relationship, allowing multiple observer objects to monitor a subject object (notifier) at the same time. When the subject object observes changes in the observed object, it notifies all observer objects so that they can update themselves. There are several roles involved here and their own functions:
2. Usage scenariosWhen a change to one object requires changes to other objects at the same time, and there is no need to know how many objects need to be changed 3. Give an exampleIf the dry concept description is obscure and difficult to understand, give an example from common life to explain it Scenario 1: In the office building, in front of the computer. A bunch of programmers took advantage of their boss being away on a business trip to watch NBA games on their computers, shouting excitedly from time to time. At this moment, the boss came back from a business trip and happened to see them, creating an awkward situation. Solution: In order to avoid being caught by the boss who came in when they were slacking off in the company, a few people came up with a plan to bribe the lady at the front desk. When the boss came into the company again, the girl immediately notified the programmers and asked them to return to work. Scenario 2: In the office building, in front of the computer. A bunch of programmers took advantage of their boss being away on a business trip to watch NBA games on their computers, shouting excitedly from time to time. At this time, the boss came back from a business trip. When the lady at the front desk saw the boss coming back, she immediately notified the guys watching the game. At this time, the young men quickly switched to work mode. Scenario 2 uses the observer pattern. When the boss comes back, the programmers need to change their paddling status, and the front desk lady is responsible for notifying them.
| ||||||||||||
<<: How to use bind to set up DNS server
>>: Solution to the problem of eight hours difference in MySQL insertion time
This article shares the specific code of Vue.js t...
1. Environment: CentOS7, Openssl1.1.1k. 2. Concep...
Table of contents First, let's briefly introd...
tomcat official website tomcat is equivalent to a...
Docker virtualizes a bridge on the host machine. ...
Table of contents 1. Keywords 2. Deconstruction 3...
The specific upgrade script is as follows: Dynami...
Solution to 1449 and 1045 exceptions when connect...
Keywords General The title cannot contain words l...
Table of contents Preface Prepare Summarize n way...
Table of contents Add traffic function to github+...
Chinese characters cannot be input in lower versio...
Table of contents 1. Docker enables remote access...
Network type after docker installation [root@insu...
SQL UNIQUE constraint The UNIQUE constraint uniqu...