Skip to content

EF.ObserverIntf

This unit defines the interfaces and support classes that implement a particular EF-specific flavour of the GoF Observer pattern.

This flavour introduces context strings and is designed to handle interfaces that disable reference counting, as all EF interfaces do.

IEFObserver interface

The observer interface. See GoF. This particular implementation allows for one observer to handle many subjects (and have the sender subject passed to the Update method), and manage different kinds of updates based on a context string parameter.

pascal
procedure UpdateObserver(const ASubject: IEFSubject;

Called by a subject to notify this observer of an update. ASubject is the sender and AContext an optional string describing the kind of update.

IEFSubject interface

The subject interface. See GoF.

pascal
procedure AttachObserver(const AObserver: IEFObserver);

Registers AObserver so that it receives this subject's notifications.

pascal
procedure DetachObserver(const AObserver: IEFObserver);

Unregisters a previously attached observer.

pascal
procedure NotifyObservers(const AContext: string = '');

Notifies all attached observers, passing the optional AContext string.

TEFSubjectAndObserver class

A default implementation of IEFObserver and IEFSubject. Inherit from this class whenever you need to create an observer or subject and don't have any inheritance constraint.

This class can also be embedded in order to delegate implementation to it.

pascal
procedure AfterConstruction;

Creates the internal list used to track attached observers.

pascal
destructor Destroy;

Frees the internal observer list and destroys the object.

pascal
procedure UpdateObserver(const ASubject: IEFSubject;

Default (empty) observer handler. Override to react to notifications when this object is used as an observer.

pascal
procedure AttachObserver(const AObserver: IEFObserver);

Registers AObserver (once) so that it receives this subject's notifications.

pascal
procedure DetachObserver(const AObserver: IEFObserver);

Unregisters a previously attached observer.

pascal
procedure NotifyObservers(const AContext: string = '');

Notifies all attached observers on behalf of this subject, passing the optional AContext string.

pascal
procedure NotifyObserversOnBehalfOf(const ASubject: IEFSubject;

Notifies all attached observers on behalf of ASubject, allowing this object to forward notifications for another subject it embeds.

Released under Apache License, Version 2.0.