[fpc-pascal] Question about interfaces

ml ml at brainwashers.org
Sat Mar 19 01:10:30 CET 2005

Just a curiosity.

1. Why does one have t specify:
  IMyInterface = interface
    function GetMyProp: integer;
    procedure SetMyProp(val: integer);
    property MyProp: integer read GetMyProp write SetMyProp;

As soon as you specify property in interface that costs source 1 or 2
lines of additional text. And even more when coding class that inherits
interface (interface automatically demands GetMyProp and SetMyProp).
Both functions will be in 99% declared in private part of the class.
Besides the fact that there could be a lot of properties that wouldn't
need reading or writing procedure just private variable.

Comparing to c#. c# has much more sane definition of interface. You only
specify read and write. Here is the same interface in c#, notice blind
get and put.

public interface IMyInterface {
	int MyProp { get; set; }

Wouldn't it be nicer to be able specify 

  IMyInterface = interface
    property MyProp: integer read <private> write <private>;
This would be much more flexible approach, which would not dictate two
additional routines. I'm not saying that <private> is the way to go, but
without specifying reading and writing subroutine.

2. Another little missing interface functionality:
It would be nice if one could use reserved word is for detecting
capability, for now the only way to do that is to call Supports (I think
that everybody would agree that (a is IUnknown) is much nicer than
Supports(a, IUnknown)), and unfortunately operator overloads for 

operator is (const source: TObject; data: TGUID) dest: boolean;
operator is (const source: IUnknown; data: TGUID) dest: boolean;

just report Error: Impossible operator overload.

btw. When writing about operators, why do they contain such little
possibilities. operator overloads could contain possibility for

3. This one is not some little beauty hack. So, no pressure here. But, I
must admit that I'm most interested in this answer. Classes do support
multiple interface inheritance, but interfaces don't. That cuts almost
all of the interface flexibility. Any good reasons why?


More information about the fpc-pascal mailing list