Answer the question
In order to leave comments, you need to log in
Is it possible to implement the "Singleton" design pattern using a non-private constructor?
Interested in the possibility of implementing this pattern in C # without a private constructor
---------------------------------------- -------------------------------------------------- ----------------
Expanded the question.
Is it possible to create a condition inside the constructor that would prohibit the creation of objects
Like this:
class Singleton
{
private int countInstance;
public Singleton()
{
lock (syncRoot) {
if (!countInstance == 0)
{ // код, запрещающий создание экземпляра
}
else
{
countInstanse = 1;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question