Context
The Observer Pattern de nes a one-to-many dependency between objects so that when one object changes state, all of its dependents are noti ed and updated automatically.
Imagine the life of a celebrity who has many fans. Each of these fans wants to be know of what their favorite celebrity has posted recently (images, videos, chats, etc.). So as long as the fan’s interest continues, she/he can follow this celebrity. When the fan loses interest, she/he stops following that celebrity.
Hint: ∼ Fans are observers and celebrity is a subject.
∼ Remember, a celebrity can have more than one follower
Observer is a behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.
Comments
Leave a comment