Module design_pattern_examples_rust::observer
source · Expand description
The Observer design pattern example module
The Observer pattern allows for one or more observers to react to changes in a Subject entity.
In this exercise, a number producer (the Subject) updates an internal value every time the update() method is called. Three different observers are attached to the number producer and print out the current value in different formats whenever the number is changed.
Accessed through the observer_exercise() function.
Modules
- Contains the IObserverNumberChanged trait, which is implemented on a struct and then passed to the ObserverNumberProducer struct when notifications are wanted about changes to the number in the ObserverNumberProducer struct.
- Contains the ObserverNumberProducer struct that maintains a number, along with a list of observers to changes in that number, as represented by the IObserverNumberChanged trait.
- Contains the ObserverDecimal, ObserverHexadecimal, and ObserverBinary structs representing the various observers that can be used in this Observer design pattern example.
Functions
- Example of using the “Observer” design pattern.