|
-
January 24th, 2011, 03:11 AM
#1
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.
<EventList>
<Event Type=A>
<id>1</id>
<A_Specific>
</A_Specific>
</Event>
<Event Type=B>
<id>2</id>
<B_Specific>
</B_Specific>
</Event>
<Event Type=C>
<id>3</id>
<C_Specific>
</C_Specific>
</Event>
</EventList>
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.
Thanks again
Chris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|