[Catalog] Factor out Factory from Type Class
I think we should factor out the factory methods from the Type
class. The class is currently doing too many things, and this is now showing as we introduce the Pool
proxies Pooled<T>
.
The class hierarchy implements our type system. It also provides factory methods Get_XXX()
to construct certain types. To make type comparisons cheap, we internalize constructed types directly in the factory methods in a static Pool<Type>
class variable.
We introduced thread-safe variants of our pools. It is not possible from the outside to specify what pool is used for Type
. That's bad.
Proposal
Create a template class TypeFactory<PoolType>
that provides factory methods to construct internalized types. The factory is a friend
of Type
. The TypeFactory
methods of Pool
should either be moved over to the TypeFactory
or made private
. If made private
, the factory methods of Type
should construct the objects on stack and return by value (move). This would allow the TypeFactory
to simply forward / delegate construction to the Type
class, then internalize them and move to managed heap objects if necessary.