One of the Super patterns. This is the most used patterns in OOP. Coming to the real world, we deal with Observer pattern everyday. That greats masters of design patterns the GOF have such keen observation of of real world.
Here are some of the observers in real world. "Call me" and you leave your number. How many time did it happen that you left a Mobile number or a Business Card with someone. Many times you do get a call from places where you left your number. Isn't it?
Who is the observer in the above scenario? Well, observer is someone who is extremely eager to call you when he/she finds that something interesting has come up that may be of interest to you. Observer is always looking for opportunities to call because that the most important activity in his life.
The person who left the number with the Observer is not waiting for the call right? He is going about his business and doing the activities that are of his interest and important. Suddenly he gets a call from one of the places where he left his number :-). What must or will he do?
Well! generally, we look at the number and check if it is from a recognized source. If not, then based on the importance of the activity that we are performing at that time, we pickup or not pickup the call.
The beauty of the pattern is in the loose coupling between Observer and Subscriber. The Observer is performing his duty without knowledge or dependency on subscribers activities and same with subscribers.
Here are some of the observers in real world. "Call me" and you leave your number. How many time did it happen that you left a Mobile number or a Business Card with someone. Many times you do get a call from places where you left your number. Isn't it?
Who is the observer in the above scenario? Well, observer is someone who is extremely eager to call you when he/she finds that something interesting has come up that may be of interest to you. Observer is always looking for opportunities to call because that the most important activity in his life.
The person who left the number with the Observer is not waiting for the call right? He is going about his business and doing the activities that are of his interest and important. Suddenly he gets a call from one of the places where he left his number :-). What must or will he do?
Well! generally, we look at the number and check if it is from a recognized source. If not, then based on the importance of the activity that we are performing at that time, we pickup or not pickup the call.
The beauty of the pattern is in the loose coupling between Observer and Subscriber. The Observer is performing his duty without knowledge or dependency on subscribers activities and same with subscribers.