Skip to main content

Posts

Showing posts from September 28, 2019

Observer Design Pattern In Java

Greetings!

Greetings!

Observer design pattern falls into behavioral category.

Observer design pattern is useful when we have multiple objects doing things according to another objects changes.
This main object is callsed Subject and depending objects are called Observers.

Subject and observers are loosely coupled and have no knowledge of each other. Subject(one) ----> Observer(many)
Swing event listner, Spring listner are some examples for Observer desgin pattern.

Observer design pattern according to GoF,
"Define a one-to-many dependency between objects so that when one object changes state, all its dependencies are notified and updated automatically."


Subject Maintain a list of observers who are interested in getting notified when something useful is happend.
This provides methods to register the Observer, unregister the Observer and a method to notify all Observers at once.

Observer Object which is interested in Subject's changes. Has a method to get updates from the …