[fpc-pascal] Traits Proposal
Ryan Joseph
genericptr at gmail.com
Wed Feb 17 16:22:51 CET 2021
> On Feb 17, 2021, at 6:10 AM, Sven Barth <pascaldragon at googlemail.com> wrote:
>
> Simply because no one has come around to implement it yet. The class type case is more complicated than the interface case. (Same would be true for record and objects)
> So, yes, we'll need to implement this first which would finally bring FPC up to Delphi compatibility regarding interface delegation.
So "class type method resolution" is what's missing? I never used the interface method resolution so I don't really understand this feature. What needs to happen as far as the compiler is concerned?
What if you want to implement virtual methods in a base class? This is kind of the core of "composition over inheritance" so it needs to be handled via method resolution I assume.
========================
(*
* Shape
*)
type
TShape = class
protected
procedure Draw; virtual; abstract;
end;
(*
* Circle
*)
type
ICircle = interface
procedure Draw;
end;
type
TCircle = class(ICircle)
procedure Draw;
end;
(*
* My Shape
*)
type
TMyShape = class(TShape, ICircle)
private
m_circle: TCircle;
protected
procedure ICircle.Draw = Draw;
public
property circle: TCircle read m_circle implements ICircle;
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list