39 Console.WriteLine(
"Observer Exercise");
61 for (
int index = 0; index < 10; ++index)
63 Console.WriteLine(
" Update {0} on number producer. Results from observers:", index);
73 Console.WriteLine(
" Done.");
Example of using the Observer Pattern in C#.
void Run()
Executes the example for the Observer Pattern in C#.
Represents an observer that prints out the current number from the Subject in binary.
Represents an observer that prints out the current number from the Subject in decimal.
Represents an observer that prints out the current number from the Subject in hexadecimal.
Represents the Subject in this example, in this case, a class that contains a single number that is u...
void Update()
Update the number then notify all observers.
Represents a Subject that takes observers implementing the IObserverNumberChanged interface.
void SubscribeToNumberChanged(IObserverNumberChanged observer)
void UnsubscribeFromNumberChanged(IObserverNumberChanged observer)
The namespace containing all Design Pattern Examples implemented in C#.