1. Classic example: publisher + subscriber = observer Mode
1.1 brief introduction to classic examples
* Publishers publish books * subscribers subscribe to books from publishers. As long as you subscribe to books all the time, the books will be delivered to you every month (monthly) * When you don't want to read this book (for example, the quality 《ProgramMember), then you can cancel this subscription * as long as the publisher is still there, someone will definitely subscribe or cancel the subscription (even if the quality is poor, someone will read "programmer")
1.2 introduce annoying examples in life (miserable experiences of the company's "Party and brother)
The conflict between China Mobile and China Mobile's customers is irreconcilable. In this case, we inadvertently subscribe to the service information that the third party cooperates with China Mobile or that of China Mobile to promote customer consumption through despicable means.
When I went out for dinner at noon, the "party elder brother" was puzzled and said it was free of charge. As soon as I pressed it, I deducted 7.5 yuan. Cup. I also ridiculed: who makes your mobile phone so good? In fact, if your mobile phone can call, you can send text messages.
You don't need that many features. They are all "a pitfall in front of a beauty who has taken off his clothes"-let you fall into it without knowing it.
OK. The conflict between mobile phone users and mobile users is irreconcilable. This is an observer mode.
2. Conflict between mobile phone users and mobile companies
2.1 discover observers and themes
Here, the mobile company's service information is the subject, and the mobile client is the observer. Party brother is an observer. If a mobile company has any means (Service Information) that can "trick" customers into money, it will notify our "party and brother" Victims (mobile customers ). Of course, it's not all strange about mobile. It may also be sent by a third party using a mobile intermediary.
The party's brother accidentally fell into that trap. Of course, if he is willing to continue to enjoy the 7.5 yuan service fee every month, it would be okay. Of course, mobile will not be idle, as soon as a new service is available, it will continue to be sent to you, making you fall into that beautiful lie again. The Service will continue in January if the mobile service is no longer available for one day.
In the face of such a tragedy, the party and brother will naturally be very angry. nnd China Mobile, I want to cancel the hateful service and never send service information again. OK. I disabled my GPRS function and no longer accept service information. OK. In this way, the tragedy will not continue.
3. A brief UML diagram is shown below:
4. The program implementation is as follows: