<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix"><br>
On 11/02/2021 03:07, Ryan Joseph via fpc-pascal wrote:<br>
</div>
<blockquote type="cite"
cite="mid:C979B111-A7FA-4616-82C6-7EB143A69386@gmail.com">
<pre class="moz-quote-pre" wrap="">
We get the shared namespace </pre>
</blockquote>
So basically, we get the compiler to automatically create forwarder
methods for us (or at least that behaviour). And that is all there
is. right?<br>
<br>
In that case IIRC, it was said traits are not allowed constructors.
Why?<br>
Now a constructor would and should not have a forwarding method, but
that the compiler can skip.<br>
Yet, in my code, in the constructor of the TMyClass, I could add <br>
_traitA.Create<br>
even<br>
_traitA := TTraitA.Create; // if the trait was not an object, but
another class.<br>
<br>
The compiler can with no doubt create the forwarder methods. And if
I understand right, then that is all the compiler should do?<br>
(Not that I advertise a trait should be a class / IMHO better not)<br>
<br>
<br>
<blockquote type="cite"
cite="mid:C979B111-A7FA-4616-82C6-7EB143A69386@gmail.com">
<pre class="moz-quote-pre" wrap="">procedure TMyClass.DoThis;
begin
// resolve the conflict by directly referencing the trait
traitA.DoThis;
end;
</pre>
</blockquote>
This we already can do. Write our own forwarder method.<br>
I understand it is for conflict resolution only. But see my example
=> as soon as you need to repeat a trait with just a change in
name, you always need conflict resolution.<br>
IMHO, there are many traits that a class could need more than once.<br>
<br>
Also that only works, if a trait is included as a field.<br>
There was at least one message in this mail-thread that suggested<br>
TMyClass = class(TObject, TTraitA);<br>
<br>
The solution is on
<a class="moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/Trait_(computer_programming)">https://en.wikipedia.org/wiki/Trait_(computer_programming)</a><br>
<blockquote type="cite"><i>alias</i>: an operation that creates a
new trait by adding a new name for an existing method</blockquote>
Doing that for all methods, means having 2 identical traits, but
with different names. => no conflict.<br>
<br>
<br>
<br>
</body>
</html>