[Issue 2295] automatically covariant types

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 19 15:00:45 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2295





------- Comment #2 from fawzi at gmx.ch  2008-08-19 17:00 -------
I think that almost the only reason a method returns always this is to allow
call chaining and replace

 a.f; a.g; a.h;

with

 a.f.g.h;

if you have a class B:A then you cannot mix B methods with a methods using call
chaining.

it would be perfectly safe to have

  typeof(b.methodA())==B

if methodA returns this for the purpose of call chaining.

Call chaining is quite likely to be used for streams, serializers and similar,
and having the subclasses to have to wrap all the interface is not nice to be
able to use an extended set of chainable methods.

An automatic subclass mixin could also be a solution (and it would also allow
automatic decoration of other methods in the subclass), but also more
dangerous... a solution only for this problem which I think is common enough
would be ok for me, the problem is I think common enough to warrant it.


-- 



More information about the Digitalmars-d-bugs mailing list