[fpc-devel] Interfaces documentation suggestion

Sergei Gorelkin sergei_gorelkin at mail.ru
Mon Aug 10 12:52:48 CEST 2009


Graeme Geldenhuys wrote:
> Hi,
> 
> Below is part of the Interfaces documentation. I disagree with the 
> documentation mentioned below.
> 
> ================================
> Interfaces - section 7.1
> http://lazarus-ccr.sourceforge.net/fpcdoc/ref/refse34.html#x77-850007.1
> 
> "There are no visibility specifiers. All members are public (indeed, it 
> would make little sense to make them private or protected)."
> ================================
> 
This is about visibility of the methods/properties of the interface itself.
Do not confuse it with visibility of interface methods in implementor 
object, where usual visibility rules (described elsewhere) apply.

> Maybe it is just Joanna Carter and myself that disagree with this 
> statement. But here goes... Joanna and I both agree that Interfaces when 
> implemented in classes should rather be made private or protected 
> instead of public.
> 
Indeed, in the implementors it makes certain sense to reduce visibility 
of interface methods, so they can be called only via interface and not 
via object instance. But this is more related to the design of 
particular application/library, than to the language specification.

> The reason is simple. You are supposed to (or preferred to) access the 
> methods via a Interface from another object instance and not the object 
> instance itself - in which case, even if the methods are private or 
> protected you will still have access to them via the Interface. Also the 
> object who implements the Interface will be able to access the methods 
> either way. But from another object instance - it is always preferred to 
> access those methods via a Interface.
> 
> Example:
> 
> var
>   lFilter: ItiFiltered;
>   lCriteria: TtiCriteria;
> begin
>   lCriteria := nil;
> 
>   if Supports(Visited, ItiFiltered, lFilter) then
>   begin
>     if lFilter.HasCriteria then
>       lCriteria := lFilter.GetCriteria;
>   end;
> ...
> end;
> 
> 
> It might be worth mentioning this, instead of simply saying that there 
> is no point in having the Interface methods implemented as private or 
> protected. Also it (Borland docs) does say that there are no visibility 
> specifiers, but where does it say they are Public by default? That is 
> just wrong.
> 
> 
> Regards,
>   - Graeme -
> 
Regards,
Sergei



More information about the fpc-devel mailing list