Filtering events
As said in the previous section, it is time to alter message flow.
The observable
interface has the task of producing messages, while conversely observer
consumes such messages. To create a message filter, we need to create an object that is both a publisher and a subscriber together.
The implementation must take into consideration the filtering need and the message routing to underlying observers that subscribe to the filter observable
object instead of the main one.
Here's an implementation of the filter:
/// <summary> /// The filtering observable/observer /// </summary> public sealed class StringMessageFilter : IObservable<string>, IObserver<string>, IDisposable { private readonly string filter; public StringMessageFilter(string filter) { this.filter = filter; } //the observer collection private readonly List<IObserver<string>> observerList...