This details the definition, applicabiltiy, advantages and disadvantages of Observer Pattern. This details about when to use Observer pattern and when not to use it. The Observer is also known as Behavioural pattern. it also defined the one-to-many relationships
Defintion
When one object changes its state, all its observers(or dependents) are notified and updated automatically. This pattern used to maintain the consistency between the related objects. Observer Pattern is also called as "Publish - Subscribe" mechanism.
Applicability
Will be used when a change in one object requires a changing in another object.
When one object depend on the other
Widely used in GUI Applications(Model - View - Controller)
Use this pattern to reduce coupling
Disadvantages
Memory Leak: If domain objects observed other domain objects, When we are out of that scope we need to delete that domain objects. Because along with the objects it will hold the observer relation ship. Long lived unused objects may lead to memeory leak
It is not clear in advance how amny and which objects will be notified due to the state change