Hey. Help to deal with this template. What is it and how to use it.
- oneOn Habré enough info! - Palmervan
1 answer
Example: There is a company CompanyA (Observer) and there is a human HumanA (Subject). CompanyA releases news, this news is interesting to HumanA. To receive them, he must subscribe to this news for CompanyA. For this, a HumanA person must implement a method in which he will receive news from the company. The company, on the other hand, must implement the methods: Subscribe, unsubscribe which any object (Subject) can use by passing itself as a parameter. The Observer stores an Array sheet of these objects (Subject). When news is released at CompanyA, it notifies all subjects (Subject) that it has news, for this it sends to the method that they implemented (example: updateNews (News {String})) news. Subject gets this news into the method and does with it what it needs.
Roughly speaking, this is a subscription as an event. When a change is made in the observer, it notifies subscribers that a change has occurred, and sends data (or does not send).
There is another good example on Wikipedia , a meteorological station. When changing, it sends the temperature value to all subscribers (thermometers and so on)
- Thank you. I understand it. On Habre it is very difficult to write for a person who does not have a strong knowledge. You should already have it with an average base for this topic - zloctb
- Maybe the other way around ?: An observer (he is also an observer, also called a listener) is a person who is waiting for news. A subject (siren) is a company that releases news. The human observer subscribes to the news and waits. The company annunciator through a special mechanism (interface) notifies everyone who has subscribed. Well, an example for understanding. Ru.wikibooks.org/wiki/Java/Listeners - user2931517