What is Observer Design Pattern in Java ?

In Observer design pattern, there is a Subject that maintains the list of Observers that are waiting for any update on the Subject. Once there is an update in Subject it notifies all the observers for the change.

E.g. In real life, students are waiting for the result of their test. Here students are the observers and test is the subject. Once the result of test is known, testing organization notifies all the students about their result.

The most popular use of Observer pattern is in Model View Controller (MVC) architectural pattern.

Main issue with Observer pattern is that it can cause memory leaks. The subject holds a strong reference to observers. If observers are not de-registered in time, it can lead to memory leak.



You May Interest

What is the Use of Jsp:useBean in JSP ?

What is the Difference Between DOM and SAX Parser in Java ?

What are the Thread-safe Classes in Java Collections Framework ?

What is the Reason For Overriding equals Method in Java ?

Why Do We Use JSP Instead of Servlet in Java ?