I have following piece of code:
class A
{
public C GetC()
{
return new C();
}
}
class B
{
//has access to A but can not create C. Must ask A to create C.
private void method()
{
A a = new A();
C c = a.GetC();//Ok!
C c2 = new C();//Not allowed.
}
}
class C
{
}
What access modifiers should be used on C so it is ONLY accessible through A? (only class A knows how to properly initialize class C)
Or is there a better solution?
If you make A a nested class in C it should work.