Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Please comment on this class hierarchy design
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Avi Abrami, post: 530376"] 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. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Please comment on this class hierarchy design
Top