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

Does Java Allow Virtual Functions ?

What are the Different Scopes of a JSP Object ?

What is the Use of a Dictionary Class in Java ?

How Can You Make an Object Eligible for Garbage Collection in Jav ...

How Will You Implement Error Page in JSP ?