[fpc-devel] Interfaces documentation suggestion

Graeme Geldenhuys graemeg at opensoft.homeip.net
Mon Aug 10 10:12:49 CEST 2009


Below is part of the Interfaces documentation. I disagree with the 
documentation mentioned below.

Interfaces - section 7.1

"There are no visibility specifiers. All members are public (indeed, it 
would make little sense to make them private or protected)."

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.

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.


   lFilter: ItiFiltered;
   lCriteria: TtiCriteria;
   lCriteria := nil;

   if Supports(Visited, ItiFiltered, lFilter) then
     if lFilter.HasCriteria then
       lCriteria := lFilter.GetCriteria;

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.

   - Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal

More information about the fpc-devel mailing list