Observer Pattern
Learn Observer Pattern (Behavioral Patterns, Design Patterns in Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Observer Pattern defines a one-to-many dependency between objects, so that when one object (the "subject") changes state, all its dependents ("observers") are notified and updated automatically. Real-Life Example: YouTube channel subscribers get notified whenever the channel uploads a new video Newspaper/magazine subscription - all subscribers get the new edition automatically Java's own java.util.Observer (legacy) and any GUI event-listener system Why do we need Observer? To notify multiple dependent objects about a state change without tightly coupling them to the subject To let observers be...