I have seen few examples of Observer pattern.
Why does the update method in the Observer interface in some cases include a reference to the object being observed?
Doesn’t the observer know what object it is observing?
Please explain with example.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It may or may not have a reference to the Subject, depending on the concrete problem.
The Subject might only call the update() function and just set some value in the Observer, thus the Observer does not need a reference. Or it can notify the Observer that there has been a change, and the Observer will contact the Subject by the reference it has and get the new values.
Holding the reference in the implementation can also be used if the Observers have need to inform the Subject about something.