We have several slightly different classes.
class A{} class B{}
we have Generic , which is a collection of objects of the above classes
class Gen<T>{}
The Gen<A>
and Gen<B>
collections must exist in a single copy. If I understood the documentation correctly, it’s impossible to make a singleton from a generic. To control the creation of collections, we use something like a factory method:
class CollectionManager{ private static readonly CollectionManager _manager = new CollectionManager(); private CollectionManager(){}; public static CM {get {return _manager; }} private static Gen<A> _genA = new Gen<A>(); private static Gen<B> _genB = new Gen<B>(); public Gen<A> GenA { get { return _genA; }} ......... }
And now the question: how to prohibit the explicit creation of Gen<A>
from the program code? Those. to make the Gen<A>
instance can only be obtained from the CollectionManager
, and new Gen<A>()
in the rest of the code is prohibited.
Gen<T>
can be done completely - PashaPash ♦