Statements: detachobserver

The detachobserver statement dissolves an existing observer relation established by the attachobserver statement.

Syntax

Form 1:

detachobserverslot‑expression,object‑expression;

detachobserverslot‑expression,object‑expression,id‑expression;

Form 2:

detachobserverslot‑expression,property‑reference‑expression;

detachobserverslot‑expression,property‑reference‑expression,id‑expression;

Form 3:

detachobserverslot‑expression,null,id‑expression;

Abstract

Chora provides a unique language concept to broadcast notifications between GUI components. The connection between the sender of a notification and the affected recipients is established indirectly by associating both to a third object or property. Precisely, the interesting receiver 'attaches' itself as 'observer' to an object or property and the sender triggers the affected object or property to broadcast the notification to all registered observers. Both, the sender and the receiver don't know each other. As such, the functionality is ideal for implementing GUI application with the Model-View-Controller (MVC) software architecture pattern.

The established relations can be considered as 'weak references' and are ignored by the Garbage Collector. When the Garbage Collector reclaims an object, which is involved in an observer relation, the relation is dissolved automatically. In other words, one relation partner can't maintain alive another partner by the mere observer relation existing between them.

Object observer

In its first version, the detachobserver statement dissolves the observer relation existing between the slot method resulting from the expression slot-expression and the object specified in the object-expression. The relations are established by the attachobserver statement. Once detached, the slot method is not invoked anymore if the object is notified again by a notifyobservers statement. Already triggered but not yet delivered notifications, however, are not discarded. If the specified observer relation does not exist, nothing occurs. For example:

// The slot method 'onUpdateData' is attached as observer to the object
// 'SomeObject'
attachobserver onUpdateData, SomeObject;

// Triggers 'SomeObject' to notify all registered observers. This leads to
// the invocation of the slot method 'onUpdateData'.
notifyobservers SomeObject;

// Dissolve the observer relation. This has no effect on the pending
// slot method 'onUpdateData' invocation!
detachobserver onUpdateData, SomeObject;

[ ... ]

// This operation, in turn, does not invoke 'onUpdateData' slot method 
// anymore.
notifyobservers SomeObject;

The optional unsigned integer parameter id-expression provides an additional subdivision to distinguish between several observers attached to one and the same object. Using the id-expression allows you to address the desired observers individually. If the expression is omitted, the statement assumes automatically the value 0 (zero) for the id. For example:

// Dissolve the observer relation, established previously with a
// particular 'id'
detachobserver onUpdateData1, SomeObject;        // id = 0 assumed
detachobserver onUpdateData2, SomeObject, 1369;
detachobserver onUpdateData3, SomeObject, 0;

Property observer

In its second version, the detachobserver statement dissolves the observer relation existing between the slot method resulting from the expression slot-expression and the property specified in the property-reference-expression. The relations are established by the attachobserver statement. Once detached, the slot method is not invoked anymore if the property is notified again by a notifyobservers statement. Already triggered but not yet delivered notifications, however, are not discarded. If the specified observer relation does not exist, nothing occurs. For example:

// The slot method 'onUpdateData' is attached as observer to the property
// 'Value'
attachobserver onUpdateData, ^Value;

// Triggers 'Value' to notify all registered observers. This leads to
// the invocation of the slot method 'onUpdateData'.
notifyobservers ^Value;

// Dissolve the observer relation. This has no effect on the pending
// slot method 'onUpdateData' invocation!
detachobserver onUpdateData, ^Value;

[ ... ]

// This operation, in turn, does not invoke 'onUpdateData' slot method 
// anymore.
notifyobservers ^Value;

The optional unsigned integer parameter id-expression provides an additional subdivision to distinguish between several observers attached to one and the same property. Using the id-expression allows you to address the desired observers individually. If the expression is omitted, the statement assumes automatically the value 0 (zero) for the id. For example:

// Dissolve the observer relation, established previously with a
// particular 'id'
detachobserver onUpdateData1, ^Value;        // id = 0 assumed
detachobserver onUpdateData2, ^Value, 1369;
detachobserver onUpdateData3, ^Value, 0;

Global observer

When used in its third version, the detachobserver statement dissolves a global observer relation for the slot method resulting from the expression slot-expression. The relations are established by the attachobserver statement. With the unsigned integer id specified in the parameter id-expression you address the desired observers individually. Once detached, the slot method is not invoked anymore when the corresponding notifyobservers statement is used. Already triggered but not yet delivered notifications, however, are not discarded. If the specified observer relation does not exist, nothing occurs. For example:

// The slot method 'onUpdateData' is attached as a global observer
attachobserver onUpdateData, null, 1251;

// Notify all globally registered observers with the id 1251. This leads to
// the invocation of the slot method 'onUpdateData'.
notifyobservers null, 1251;

// Dissolve the observer relation. This has no effect on the pending
// slot method 'onUpdateData' invocation!
detachobserver onUpdateData, null, 1251;

[ ... ]

// This operation, in turn, does not invoke 'onUpdateData' slot method 
// anymore.
notifyobservers null, 1251;