mercredi 1 février 2017

How to prevent calling constructor of one class while having access to its member functions in C#?

I have a class A, and a class AStore. My requirement is to prevent all other methods from initializing an instance of class A, which they should get an instance from AStore. In addition, I also need to access the member functions of A from the instance.

Factory pattern is not suitable for this problem as the constructor of A is still public. Ideally, it should throw compilation error when calling the constructor of class A while having access to its member functions.

Can I get C# solutions to this?

Aucun commentaire:

Enregistrer un commentaire