We had talked about this some time ago and it's been rattling around in my 
brain so I wanted to write it down into a formal proposal where we can discuss 
it and hopefully agree upon a syntax. Everything is preliminary and tentative 
but this is a syntax which allows a "composition over inheritance" model, also 
known as "mix-ins" in some languages. That idea is similar to multiple 
inheritance except you have a concrete reference to the trait being implemented 
so you can resolve conflicts easily.

Here's what I have so far. Please feel free to look at it and give any feedback.

https://github.com/genericptr/freepascal/wiki/Traits-Proposal

====================

type
  TSomeTrait = trait
    public
      field: integer;
      procedure DoThis;
  end;
  
  TMyClass = class
    private
      _trait: TSomeTrait;
    public
      property someTrait: TSomeTrait implements _trait;
  end;

var
  c: TMyClass;
begin
  c := TMyClass.Create;
  c.DoThis;
  writeln(c.field):
end;

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to