Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

Jonathan M Davis newsgroup.d at
Wed Sep 26 23:32:36 UTC 2018

On Wednesday, September 26, 2018 3:24:07 PM MDT Adam D. Ruppe via 
Digitalmars-d-learn wrote:
> Object.factory kinda sux and I'd actually like to remove it
> (among other people). There's no plan to actually do that, but
> still, just on principle I want to turn people away.

While there may not currently be plans to be remove it, as there _are_ plans
to add ProtoObject as the new root class underneath Object, at some point
here, it's likely that a large percentage of classes won't have anything to
do with Object, so relying on Object.factory to be able to construct class
Objects in general isn't likely to be a viable path in the long term -
though presumably it would work for a code base that's written specifically
with it in mind.

Personally, I'm hoping that we eventually get to the point where Walter and
Andrei are willing to outright deprecate Object itself, but I expect that
ProtoObject will have to have been in use for a while before we have any
chance of that happening. Either way, I think that it's clear that most code
bases should go with a solution other than Object.factory if at all
reasonably possible.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list