0
나는 싱글 톤 패턴을 구현하고 object obj
포함하는 클래스 A
있습니다사용 필드
public sealed class A
{
static A instance=null;
static readonly object padlock = new object();
public object obj;
A()
{
AcquireObj();
}
public static A Instance
{
get
{
if (instance==null)
{
lock (padlock)
{
if (instance==null)
{
instance = new A();
}
}
}
return instance;
}
}
private void AcquireObj()
{
obj = new object();
}
}
지금 내가 A의 인스턴스를 유지할 필요가 또 다른 클래스 B가를 obj 객체가 살아있을 때까지 객체.
public class B
{
// once class A was instantiated, class B should have public A.obj
// field available to share.
// what is the best way/practice of putting obj here?
}
감사합니다.
클래스 B는 단순히 A.Instance.obj에 액세스 할 수 없습니까? 이전에 초기화되지 않았 으면 A를 초기화합니다. – Vadim
클래스 A는 클래스 B에 의해 초기화 될 수 없습니다. 클래스 A는 고유 한 초기화 방법을가집니다. – inside
"초기화 방법"이란 무엇을 의미합니까? 그것은 싱글턴이 아닌가요? – Vadim