January 24th, 2011, 02:11 AM
To use Classes that extend a base class or not
I am wondering what is the best practise for doing the following;
I am going to query an api, and it will return xml similiar to this.
I'll then use this to build an arraylist of objects. Should I;
1) Create a class with all the above fields in the 1 class of type Event, or
2) Create an Event base class with id as it's only field then 3 more classes like 'EventTypeC' that extends Event and then add the C_Specific value in this constructor?
If it's number 2, what would be the best way of taking this information then building an ArrayList<With_Multiple_Object_Types>?
Thanks in advance for the feedback. I'm assuming people will say it's a personal choice but I guess I'm looking for what is the best approach. I'm learning so would like to learn the right way, but i'm weighing up the extra effort of deciding what object i'm dealing with etc when i decide to scan the arraylist and deal with each event independantly and perform actions based on the event type.
January 24th, 2011, 04:08 AM
Re: To use Classes that extend a base class or not
If you have values that are specific to one type and are meaningless to another type then go with approach 2. Or if the behaviour of the types is different so for example you will need different method implementations for each type then again use approach 2.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.