Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-08

Interfaces documentation suggestion

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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)." ================================

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.

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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Sergei Gorelkin
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
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.

Show quoted text 5 lines
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.

Show quoted text 35 lines
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

Reply by email

Graeme Geldenhuys
to Sergei Gorelkin
Sergei Gorelkin wrote 8 lines
> > "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.

True, but from the comment in brackets I deduced that it was a reference to when they (Interfaces) get implemented. Either way, then maybe a comment needs to be added that Interfaces having no visibility specifiers when the interface is declared, does NOT mean they they must also be Public visible when implemented in a class.

I feel the wrong message is being sent in that documentation.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: Below is part of the Interfaces documentation. I disagree with the documentation…
Graeme Geldenhuys wrote 16 lines
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)." ================================ 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.

You are misinterpreting the statement. The statement is that IN THE INTERFACE DECLARATION, all the members are public.

No assumption is made about the visibility of the methods in the class that actually implements the interface.

Michael.

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: True, but from the comment in brackets I deduced that it was a reference to when they…
Graeme Geldenhuys wrote 18 lines
Sergei Gorelkin wrote: >> >> "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. True, but from the comment in brackets I deduced that it was a reference to when they (Interfaces) get implemented. Either way, then maybe a comment needs to be added that Interfaces having no visibility specifiers when the interface is declared, does NOT mean they they must also be Public visible when implemented in a class. I feel the wrong message is being sent in that documentation.

I will add a comment as you suggest. The documentation is meant to enlighten the user, not confuse him :-)

Michael.

Reply by email