Software Development and Project Management
Which GoF design pattern makes the objects that depend on an object be notified automatically when that object's state changes?
- AObserver
- BSingleton
- CAdapter
Show answer and explanation
Answer: A. Observer
In the Observer pattern, the notifying object (the subject) keeps a list of registered objects that want notifications (observers) and informs all of them when its state changes. The subject does not need to know the concrete classes of the observers, which keeps coupling weak. For example, it can be used in a design that informs display, logging and alarm processing when a sensor value changes. Singleton is a pattern that ensures a class has only one instance, and Adapter is a pattern that converts a mismatched interface so that classes can work together.
- A. Correct. Changes of state are notified to several registered objects.
- B. This pattern ensures a class has only one instance; it is not a notification mechanism.
- C. This pattern connects classes with mismatched interfaces by converting between them.
Continue: 9 more Software Development and Project Management questions