[fpc-pascal] Traits Proposal
Sven Barth
pascaldragon at googlemail.com
Mon Feb 15 07:43:04 CET 2021
Am 14.02.2021 um 19:03 schrieb Ryan Joseph via fpc-pascal:
>
>>> What it leaves desired:
>>>
>>> 1) Making a dummy interface is annoying boiler plate but not a deal breaker.
>> Again, I see this is part of Pascal's declarativeness. Also this way you can make sure that only those methods/properties that you need are hoisted into the parent object allowing for easier reuse of existing classes/records/objects.
> That is certainly true. With the idea of "default record properties"/traits the visibility sections like public would have to be used to define the exportable members. The "declarativeness" is also boiler plate but I do see your point. Not a deal breaker though but it may get tedious if you used this feature often.
One can always think about relaxations/improvements later on. As said
before: let's get the foundation down right, first.
> Another question, what does overriding mean in this context of interface delegation? With "default implements" it would be possible to add a method with the same name, which should be an error but it opens a possibility to provide a new method implementation.
Same names should be rejected. Providing a new implementation can be
controlled using the interface alias:
=== code begin ===
type
TMyClass = class(TInterfacedObject, IMyIntf)
private
fMyRecord: TMyRecord;
public
procedure IMyIntf.Test2 = MyTest2;
// this will hoist all methods except Test2 from TMyRecord and
MyTest2 as Test2 from the class itself
property MyRecord: TMyRecord read fMyRecord implements IMyIntf;
default;
propcedure MyTest2;
end;
=== code end ===
Regards,
Sven
More information about the fpc-pascal
mailing list