[fpc-devel] Interfaces documentation suggestion
sergei_gorelkin at mail.ru
Mon Aug 10 12:52:48 CEST 2009
Graeme Geldenhuys wrote:
> 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)."
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.
> 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 -
More information about the fpc-devel