I am there,
I have a scenario like this:
public class A{
}
public class B{
}
public class C{
private B b;
}
public class D{
private C c1, c2, c3;
private List<A> a;
}
Each class has its own file. However, I would like to get classes A, B and C as inner classes of class D, because I do not use them in the whole program, just in a small part. How do I implement them? I read about this, but I'm still not sure what is the best alternative:
Option 1 using static classes:
public class D{
static class A{
}
static class B{
}
static class C{
private B b;
}
private C c1, c2, c3;
private List<A> a;
}
Option 2 using an interface and a class that implements it.
public interface D{
class A{
}
class B{
}
class C{
private B b;
}
}
public class Dimpl implements D{
private C c1, c2, c3;
private List<A> a;
}
I would like to know which approach is better to get the same behavior using the original script. Is it ok if I use Option 1 and use classes like this?
public method(){
List<D.A> list_A = new ArrayList<D.A>();
D.B obj_B = new D.B();
D.C obj_C1 = new D.C(obj_B);
D.C obj_C2 = new D.C(obj_B);
D.C obj_C3 = new D.C(obj_B);
D obj_D = new D(obj_C1, obj_C2, obj_C3, list_A);
}
, , outter. A, B C, D. , ?