[fpc-pascal] Traits Proposal

Sven Barth pascaldragon at googlemail.com
Sun Feb 14 11:31:27 CET 2021


Am 14.02.2021 um 01:09 schrieb Ben Grasset via fpc-pascal:
> This seems possibly a *little* too similar to the existing Interface 
> type in Object Pascal, however, I *would* really like to see some kind 
> of functionality that basically amounts to "has the same capabilities 
> as Interfaces and works on records and objects too, but does NOT 
> require any kind of heap allocation".

My personal idea for this would be to allow for duck typing regarding 
interfaces: as long as the methods of the class, object or record 
satisfy those of the interface then it's possible to assign it. In case 
of objects and records one would mainly use raw interfaces (aka corba 
ones) instead of reference counted one as otherwise one would need to 
provide the methods of IInterface as well though one might not be able 
to implement them in a usable way as stack objects simply don't work 
that way.

> So whether it be this, or just an improvement on the Interfaces we 
> already have, I'd definitely personally be in favor of something that 
> "works like Interfaces except minus the negative performance 
> implications."

There are no significant performance implications of interfaces. They're 
essentially a virtual method call, something that one is doing all day 
long with Object Pascal classes.

Regards,
Sven


More information about the fpc-pascal mailing list