Request to change interface of the new observer support
Original Reporter info from Mantis: luizamerico
-
Reporter name: Luiz Americo
Original Reporter info from Mantis: luizamerico
- Reporter name: Luiz Americo
Description:
I request to change the interface of FPODetachObserver / FPOAttachObserver procedures of IFPObserved
from
Procedure FPOAttachObserver(AObserver : TObject);
Procedure FPODetachObserver(AObserver : TObject);
to
Procedure FPOAttachObserver(AObserver : IFPObserver);
Procedure FPODetachObserver(AObserver : IFPObserver);
Reasons:
- Sometimes is not possible to know the object instance class and therefore if it implements IFPObserver. This leads to redundant interface check.
Example 1: in a class/object factory with the possibility to register different classes, is not possible to know beforehand if an specific interface is implemented by the returned class so the need to check before use an interface.
Example 2: i'm developing a LCL wizard manager where is possible to set a TControlClass to a page. Optionally this class can implement an interface so i need to check if implements this interface before using it.
In both cases, if IFPObserver is being used there would be two redundant interface checks for the same object, one in the caller and another inside FPODe/AttachObserver
- In some situations only the interface address is know therefore is not possible to call FPODe/AttachObserver
Example: a parent object (e.g. a LCL control) has an Observer: IFPObserver property. This object is responsible to attach child objects to this observer. Currently is not possible because from IFPObserver i cannot get a TObject instance. In the other hand if i have a TObject i can get an IFPObserver
-
Changing the parameter to IFPObserver will improve compile time type check minimizing chances of programming errors as the programmer passing an object of a class that does not implements the interface. It would be clearer for the programmer that it must pass an IFPObserver.
-
Implementation of FPOAttachObserver, FPODetachObserver and FPONotifyObservers would be simplified and optimized since there would be no need to call GetInterface every time attach, detach and principally at notify actions
I can implement such changes (with necessary code adaptation) and send the patches in a reasonable time.
Mantis conversion info:
- Mantis ID: 23394
- Monitored by: » @mdbs99 (Marcos Douglas)