A
シングルトンパターンを実装し、以下を含むクラスがありますobject obj
:
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();
}
}
これで、別のクラス B があり、A.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?
}
ありがとうございました。