TSender provides an interface, GetValueChangedInterest, that receivers will use to express interest in particular notifications. This creates an interest that specifies the notifier (the same as TSender, as it inherits from TNotifier) and a token to distinguish this interest from others.
TSender calls Notify, sending a standard notification with the interest defined above, when it makes a change that it wants to notify receivers of.
TReceiver provides this instance with an object and member function to call when notifications are received. In this sample, it does this in the constructor, because its initialization is complete at this time. (Other receivers might have to delay setting up the constructor until later.)
TReceiver uses the protocol of TSender to get an interest in changes by the sender it listens to, and tells the connection to inform it when the connection receives notifications sent using that interest.
TReceiver calls Connect on its connection to start receiving notifications.
The order of calls to Connect and to AddInterest is not important. Interests can be added and removed, and connections connected and disconnected, at any time.
Take special care to ensure that the notifier is not destroyed before the connection. Otherwise, when the connection is destroyed, it will attempt to disconnect from the notifier using an invalid pointer, resulting in a bus error.
This technique of defining TSender protocol to create interests is typical. TInterest is quite lightweight, so copying it is not a problem. This also hides the actual notifier used in the TInterest, allowing later versions of TSender to use a different notifier instead of inheriting from one. Receivers cannot assume that the notifier in the interest can be coerced to the class of the sender.