Instance and Type based subscriptions

Instance- and type-based subscriptions

Status: IsProposal

Author

JimFulton

Problem

Sometimes, we want to subscribe to events only for specific objects or for specific types of objects. For example, we currently have notification interfaces, IAddNotifiable? and IRemoveNotifiable? that we call when objects are added or removed. These are used to implement class-specific notification policies. These are currently provided via methods on the objects we add or remove. It would be cleaner if these could be handled as subscribers that are called when objects of a particular type are added or removed. Why? If there are multiple actions we want to perform, we currently have to put them all in the same method. If we change what we want done, we might have to update multiple methods. Subscriptions would let us keep these actions separate.

Similarly, we have a dependency framework essentially for defining integrity constraints among objects. We prevent objects from being deleted if they have dependents. This mechanism is fairly crude. We might, in some cases, perform some action on a dependent object when the object it depends on is removed. In any case, we want to be able to subscribe to events on the affected object.

Proposal

Provide the following mechanisms:

  1. Type-based subscriptions through adapters

    For object events, get subscription adapters from the affected object and event to ISubscriber?. Subscriptions can thus be registered for any of an object's interfaces, or even for its class.

    Note that subscription adapters were added for this purpose.

  2. Instance-based subscriptions

    For object events, we'll adapt the object to ISelfSubscriber?:

              class IInstanceEventChannel(IEventChannel):
                  """Objects that support instance-based subscriptions
                  """
    

    and call its notify method.

    Similarly, to subscibe to events for an instance, we'll get an IInstanceEventChannel? adapter and call it's subscribe method.

    We'll provide an adapter from IAnnotatable? to ISubscriptions?.

Note that both of these policies can be implemented with global subscribers to object events. The policy need not be implemented in the event service itself.

We will replace the current IAddNotifiable? and IDeleteNotifiable? frameworks with type-based subscribers.

We will replace the dependence framework with instance-based subscribers.



( 97 subscribers )