volume_mute
Observer Pattern - Four Objects
publish date: 2026/06/12 10:18:11.914328 UTC
volume_muteThe Observer pattern involves two abstract objects and two concrete objects. Match each object to its role.
To complete the line match
- Click on an item in the first group
- Click on the match in the second group
To delete a match, double click on a line
Object
Observer
Subject
ConcreteObserver
ConcreteSubject
Role
Abstract object that maintains state and provides Attach, Detach, and Notify operations; does not know details of the concrete class
Abstract object that defines the Update() interface that all observers must implement
Inherits from Subject; maintains subjectState and provides GetState(); notifies observers when state changes
Inherits from Observer; maintains a copy of subjectState and implements Update() to keep its copy in step with the subject
Correct Answer
(1) Subject,Abstract object that maintains state and provides Attach, Detach, and Notify operations; does not know details of the concrete class
(2) Observer,Abstract object that defines the Update() interface that all observers must implement
(3) ConcreteSubject,Inherits from Subject; maintains subjectState and provides GetState(); notifies observers when state changes
(4) ConcreteObserver,Inherits from Observer; maintains a copy of subjectState and implements Update() to keep its copy in step with the subject
Explanation
The Observer pattern's four objects: Subject (abstract) - manages state and the observer list (Attach/Detach/Notify); Observer (abstract) - defines the Update() interface; ConcreteSubject - the actual object whose state is tracked (GetState, subjectState); ConcreteObserver - each observer that maintains a copy of the state and implements Update(). The Subject only knows the abstract Observer, providing minimal coupling.
Reference
Software Engineering, Ian Sommerville, 10th edition
