shlogg · Early preview
Prashant Mishra @prashantrmishra

Observer Pattern In Java With YouTube Channel Example

Observer pattern used for one-to-many relationships where changes to subject notify dependent objects. Example: YouTube Channel and subscribers.

Observer pattern is used when there is one to many relationship between objects such as if one object is modified, its dependent objects are to be notified automatically. Observer pattern falls under behavioural pattern category.
Example: a Youtube Channel and its subscribers
It is also called pub sub model
Whenever new contents in the youtube channel is added or existing content is modified, all the subscribers of the youtube channel will be notified
Let's understand the same example

Subject or YoutubeChannel

package Patterns.Behavioral.observer;
import java.util.ArrayList;
import java.util...