A
Avi Abrami
The following code is a minimalized version of a class
hierarchy, designed by one of my co-workers, that is
part of our java application software. He insists that
it is a good design, but I, and several other co-workers,
think it is a bad design. What do you think?
(Note: I'm not asking for alternatives, just whether you
think it's good -- or bad -- and why.)
public abstract class A {
protected static final int CHILD_TYPE_B = 0;
protected static final int CHILD_TYPE_C = 1;
protected BMember bMember;
protected CMember cMember;
protected Collection bList;
protected Collection cList;
private int childType;
// Constructor
public A(int type) {
childType = type;
switch (childType) {
case CHILD_TYPE_B:
bMember = new BMember();
bList = new ArrayList();
break;
case CHILD_TYPE_C:
cMember = new CMember();
cList = new ArrayList();
break;
}
}
}
public class B extends A {
//Constructor
public B() {
super(CHILD_TYPE_B);
}
}
public class C extends A {
// constructor
public C() {
super(CHILD_TYPE_C);
}
}
public class Member {
}
public class BMember extends Member {
}
public class CMember extends Member {
}
Thanks (in advance),
Avi.
hierarchy, designed by one of my co-workers, that is
part of our java application software. He insists that
it is a good design, but I, and several other co-workers,
think it is a bad design. What do you think?
(Note: I'm not asking for alternatives, just whether you
think it's good -- or bad -- and why.)
public abstract class A {
protected static final int CHILD_TYPE_B = 0;
protected static final int CHILD_TYPE_C = 1;
protected BMember bMember;
protected CMember cMember;
protected Collection bList;
protected Collection cList;
private int childType;
// Constructor
public A(int type) {
childType = type;
switch (childType) {
case CHILD_TYPE_B:
bMember = new BMember();
bList = new ArrayList();
break;
case CHILD_TYPE_C:
cMember = new CMember();
cList = new ArrayList();
break;
}
}
}
public class B extends A {
//Constructor
public B() {
super(CHILD_TYPE_B);
}
}
public class C extends A {
// constructor
public C() {
super(CHILD_TYPE_C);
}
}
public class Member {
}
public class BMember extends Member {
}
public class CMember extends Member {
}
Thanks (in advance),
Avi.